Created
September 7, 2015 12:11
-
-
Save jchristopher/6ed601fc143a164c957b to your computer and use it in GitHub Desktop.
Exclude entries within a taxonomy term from SearchWP's search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_searchwp_exclude( $ids, $engine, $terms ) { | |
$entries_to_exclude = get_posts( | |
array( | |
'post_type' => 'any', | |
'nopaging' => true, | |
'fields' => 'ids', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'category', | |
'field' => 'slug', | |
'terms' => array( 'category-1' ), | |
), | |
), | |
) | |
); | |
$ids = array_unique( array_merge( $ids, array_map( 'absint', $entries_to_exclude ) ) ); | |
return $ids; | |
} | |
add_filter( 'searchwp_exclude', 'my_searchwp_exclude', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment