Reputation: 2285
How to I can remove posts from a specific category from homepages in wordpress? I want to do it by category's name or id or ...
I use the loop to get my posts like these:
if (!have_posts()) : while (have_posts()) : the_post();
thanks a lot
Upvotes: 0
Views: 1507
Reputation: 90
you can use this function, there's no need to know what your cat-id is, just use the category-slug:
function exclude_category($query) {
if ( $query->is_front_page ) {
$category_ID1 = get_cat_id(category_slugA);
$category_ID2 = get_cat_id(category_slugB);
$query->set('cat',"-$category_ID1 -$category_ID2");
} return $query;
} add_filter('pre_get_posts', 'exclude_category');
Upvotes: 2
Reputation: 171
I recommend Advanced Category Excluder. Very easy to use. Almost painfully easy to use.
Upvotes: 1
Reputation: 117
You could try using this plugin: wordpress.org/extend/plugins/front-page-excluded-categories You might also try adding this code to your 'functions.php':
<?php function excludeCat($query) { if ( $query->is_home ) { $query->set('cat', '-3,-5,-23'); } return $query; } add_filter('pre_get_posts', 'excludeCat'); ?>
where -3, -5 and -23 are the category ids you want to remove.
Upvotes: 1