Need help to exclude posts from home page
-
I am trying to exclude posts from my index page. I have the below code in my functions.php to accomplish that:
function my_cat_exclude($query) { if ($query->is_home) { //$query->set('cat','-1,-3,-4,-5,-6,-7,-8,-9,-10'); $query->set('cat','11'); } return $query; } add_filter('pre_get_posts','my_cat_exclude');
I have 12 categories in my blog. I would like to show posts from only one category (category id 11). I don’t want to show the rest on homepage.
If I use
$query->set('cat','-1,-3,-4,-5,-6,-7,-8,-9,-10');
it doesn’t show posts which shares the same category with category id 11. For example, if a post is assigned to two categories category id 5 and category 11, then, it doesn’t shows that post in my home page. I would like to show all posts belong to category id 11 on my home page.If I use
$query->set('cat','11');
It shows only category with category id 11. however, it removes the other category posts, custom menus from sidebar widget. Also, removes the menu items from top menu.Please help.
Thanks
- The topic ‘Need help to exclude posts from home page’ is closed to new replies.