Problem ID to exclude specific posts from category
-
Hi, everybody
I’m trying to exclude specific posts from category/archive with these functions:
function exclude_single_posts_cat($query) { if ( is_admin() || ! $query->is_main_query() ) return; if ($query->is_archive() ) { $query->set('post__not_in', array('1','2','3'));}}
– I’ve also tried (‘-1′,’-2′,’-3′) or without quotes.add_action('pre_get_posts', 'exclude_single_posts_cat',);
Or:
function exclude_single_posts_cat($query) { if ($query->is_category() AND $query->is_main_query()) { $query->set('post__not_in', array('1','2','3'));}}
– I’ve also tried (‘-1′,’-2′,’-3′) or without quotes.add_action('pre_get_posts', 'exclude_single_posts_cat');
But something happens that I can’t explain, that is, there disappear posts that don’t correspond to the specified ID (following the example, the hidden posts may be ‘4’, ‘5’, ‘6’ ). Could someone tell me why it happens and where I’m wrong, please?
Thank you in advance.
- The topic ‘Problem ID to exclude specific posts from category’ is closed to new replies.