Excluding a category when using get_posts
-
Hi,
I was using the following code:
$posts = get_posts('numberposts=8&order=desc&orderby=post_date');to retrieve 8 latest posts orered by posting date in single.php and on my site’s homepage (not blog).
foreach ($posts as $post) : start_wp();All was fine till I needed to filter out a certain category, say ’25’. Using
if (in_category('25')) continue;wouldn’t work because it would return only 6 entries if there’re 2 category ’25’ posts found as documented in the DOC.If I use
query_posts("cat=-25")before the start of$post, it will return only 2 posts and not 8.Question is, how do I filter out a certain category while listing out 8 latest posts?
Thanks in advance.
The topic ‘Excluding a category when using get_posts’ is closed to new replies.