Exclude Certain Category Posts From the Blog Page
Feb 12, 2016 6:50 pm No comment
The correct way to exclude categories from main blog page, is to make use of pre_get_posts
which change the query variable before the main query is executed. The following is an example;
function exclude_category($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set(‘cat’, ‘-3,-6’);
}
}
add_action(‘pre_get_posts’, ‘exclude_category’);
For the full list of available parameters you can use with pre_get_posts
, please visit WP_Query codex page.
Categories: Tutorials