How to display non related posts after related posts?
-
Related = Identical tags
So I am able to display two related posts in a post. But if I can’t find any related posts I want to display any other posts in the category.
$the_cat = get_the_category(); $cat_id = $the_cat[0]->cat_ID; $the_query = new WP_Query(array('category__in' => $cat_id, 'post__not_in' => array($id), 'orderby' => 'rand', 'posts_per_page' => 2, 'tag' => 'Omega,Seamaster')); if( have_posts() ) : while ($the_query->have_posts()) : $the_query->the_post();
The long way I can do this is count to see how many related posts I retrieve and then run another query if I need to.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to display non related posts after related posts?’ is closed to new replies.