Skip to content

Commit 034a40b

Browse files
committed
Exclude category from archive
1 parent 6673ff9 commit 034a40b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
add_action('pre_get_posts', 'my_exclude_category_from_archive');
4+
function my_exclude_category_from_archive($query) {
5+
// Exclude from the main archive, but display on the category archive
6+
if($query->is_main_query() && $query->query['category_name'] !== 'custom-category-slug') {
7+
// Put category ID in the array
8+
$query->set('category__not_in', array(10));
9+
}
10+
}

0 commit comments

Comments
 (0)