Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created September 7, 2015 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/6ed601fc143a164c957b to your computer and use it in GitHub Desktop.
Save jchristopher/6ed601fc143a164c957b to your computer and use it in GitHub Desktop.
Exclude entries within a taxonomy term from SearchWP's search
<?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