ID); // get category object $category_ids = array(); // set an empty array $blook_related_post_number = 3; foreach ($post_categories as $post_category) { $category_ids[] = $post_category->term_id; } if (empty($category_ids)) return; $qargs = array( 'posts_per_page' => $blook_related_post_number, 'category__in' => $category_ids, 'post__not_in' => array($post->ID), 'order' => 'ASC', 'orderby' => 'rand' ); $related_posts = new WP_Query($qargs);// custom posts ?>

have_posts() ): $related_posts->the_post(); if (has_post_thumbnail()) { $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'medium_large'); $featured_image = isset($featured_image[0]) ? $featured_image[0] : ''; } ?>