Using the example here: http://codex.wordpress.org/Custom_Queries#Category_Exclusion
I am trying to exclude posts from a specific category from home, feed, category, archives etc - in fact I only want to see the posts from this category in admin pages (and to be able to view the post in is_single). So I include this in my functions.php file:
add_action('pre_get_posts', 'remove_sold_cat' );
function remove_sold_cat() {
global $wp_query;
if (is_admin() ) {
} else {
$wp_query->query_vars['cat'] = '-5';}
}
This code works BUT if the post is in more that one category (which they will be) the post still displays when viewing the category page of the other category. Is this a bug or a feature??
So for category.php I now have to include this prior to the loop:
<?php query_posts("&cat=-5"); ?>
The posts are excluded as I expected when using the code above in functions.php BUT it screws up the paging - so I now include:
<?php query_posts($query_string.'&cat=-5'); ?>
The paging now works but the posts that are also in Category 5 are now included.
My final action is to include within the loop:
<?php if ( in_category('5') ) continue; ?>
Yes that does remove the posts as expected but again the paging is screwed.
I have tried this suggestion: http://wordpress.org/support/topic/57912#post-312858 but to no avail and found other reports of it not working with WP2.6.1.
Can anyone please point me in the right direction.