I have a custom page template that uses the wordpress loop to display all my posts like usual:
<?php if (have_posts()) : while (have_posts()) : the_post();
There is a category that I don't want to display on this page. The id of this category is 3.
So I though I could use something like this:
<?php if (have_posts()) : while (have_posts()) : the_post();
if ( in_category('3') ) continue;
the_content();
endwhile;
endif;
?>
But the posts with this category ID are still displaying.
I've also tried adding this to functions.php:
function exclude_category($query) {
if (isset($query)) {
$query->set('cat', '-3');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
This works, but it is global to every page on the site (obviously), which is what I don't want. I just want category ID removed from this single page template.
Is it possible to do this?
pre_get_posts
doesn't work on page templates. Exactly what template?