I successfully use pre_get_posts to exclude two categories from the main loop on the homepage, archive and author page. My problem is that I want to display those categories in the sidebar! Here is the code (functions.php):
function exclude_category_home($query) {
if ($query->is_home && $query->is_main_query() || $query->is_archive || $query->is_author) {
$query->set('cat', '-3,-41');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category_home');
That doesn't work. Why?
SOLVED:
function manipulation_parse_request() {
add_action('pre_get_posts', 'manipulation_pre_get_posts');
}
add_action('parse_request', 'manipulation_parse_request');
function manipulation_pre_get_posts($wp_query){
if ($wp_query->is_home || $query->is_archive || $query->is_author) {
$wp_query->set('cat', '-3,-41');
}
return $wp_query;
}