Excluding Categories From Loop But Keeping It Visible in "All Posts"

Posted in: Newsmag
Post count: 19

Currently I’m using this code:
function exclude_cat( $query ) {
$query->set( 'cat', '-58' );
}
add_action( 'pre_get_posts', 'exclude_cat', 1 );

and it works perfectly fine to exclude the posts from my site, but it also excludes it from the “All Posts” section to where I can no longer see it.

How do I exclude this category from the website but have it still visible in the backend?

Post count: 6535

Hi

Try this code in functions.php file and add the id of category that you want to be displayed:

function exclude_category($query)
{
$query->set('cat', '-29, -23');
return $query;
}
add_filter('pre_get_posts', 'exclude_category');

Thanks!

Post count: 19

this hides it on the website but in the backend the category is still hidden there also so its the same as the code i had before, what else can i try to get the post visible in the backend?

Post count: 6535

Hi

The code works fine for me, as you can see here the category with id 23 is still in backend even if i use the code in functions.php: http://screencast.com/t/OyVMeYYqU I am not sure why this happens to you but you can try to empty all caches and test again.

Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newsmag’ is closed to new topics and replies.