From Archive Page I want to remove posts from couple of categories, as they have different style formats which will not look good with other category style formats.
1 Answer
try this...
Not Tested
add_action("pre_get_posts","my_category_remove");
function my_category_remove($query)
{
if(is_archive()) {
$query->set('category__not_in', array(/*the categories (ID's) you wish not to show, comma separated*/));
}
return $query;
}
-
By
/*all the post ids*/
you meant/*the categories you wish not to show*/
? Jul 15, 2013 at 10:03 -
Yes. You should provide
id
s of all the categories you want to escape. provide theid
s separated by comma(,). Jul 15, 2013 at 10:05 -
FYI: When u visit the posts page in admin panel, you won't be able to see the posts from that category so please edit the condition as follows
if ($query->is_archive && !is_admin()) {}
Jul 15, 2013 at 10:13