[Resolved] Single – Listing posts from one current category
I’m using the code below and it gets posts from current category in single post sidebar. The posts I’m talking about have multiple categories (2 cat) assigned. It gets posts from first category if I set $category and second category if I set $category.
Also by default it gets categories sorting them by name and not by ID.
One of those category is a “Featured” cat and I don’t want to show posts from this category, but it happens when the second category has as first letter G, H, I, etc…. Also I set up this category with an ID = 9999 so it’s always the last category.
Is there a way to show posts only from lower category ID number between multiple categories assigned?
<h3>Recently Post From Same Category</h3> <ul> <?php global $post; $category = get_the_category($post->ID); $category = $category->cat_ID; $myposts = get_posts(array('numberposts' => 5, 'offset' => 0, 'category__in' => array($category), 'post__not_in' => array($post->ID),'post_status'=>'publish')); foreach($myposts as $post) : setup_postdata($post); ?> <li> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a> </li> <?php endforeach; ?> <?php wp_reset_query(); ?> </ul>
- The topic ‘[Resolved] Single – Listing posts from one current category’ is closed to new replies.