So I am excluding posts is several categories from a blog page (categories 4-11).
I am doing so using the following code:
if (have_posts()) : while (have_posts()) : the_post();
$category = get_the_category();
if($category[0]->cat_ID > 11 || $category[0]->cat_ID < 4){
continue;
}
This works to exclude the categories posts from the page but it does not retain the post count per page being 10 or whatever it is set to in the Admin.
How would I programatically decrement the post count by one for posts I skip in the WordPress Loop so I exclude the category posts i do not want but also retain the same amount of posts per page?
The easiest (but not most efficient) way to do this is to replace the global
$wp_query
by a custom query usingcategory__in
……then do the loop…
This will make the paging accurate, and you can rely on the high-level templating functions like
next_posts_link()
.Probably a more efficient way (that doesn’t throw out and replace
$wp_query
) would be to mess with the original query before it’s executed…my_parse_query
would be called on every query, including those for pages and single posts, so you would have to add some logic to the function to only addcategory__in
where it made sense.