Hi there, I found that code and I am trying to exclude some categories ID.
I use it in a single.php for most recent posts from same category like the current post is. But I have posts default in 2 groups of categories, lets say A,B,C,D and other are 1,2,3,4 … now I want to exclude all 1,2,3,4 categories and let the code display only posts from A,B,C,D category – of course just one of them for the current one.
<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>
Any idea? Thank you!
- The topic ‘Recent posts from current cat. exclude categories’ is closed to new replies.