Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SearchWP snippet to limit results to the current category page being viewed
function mySearchIncludeIds( $ids, $engine, $terms )
// if we're viewing a category page and the SearchWP engine is the default engine
if( is_category() && $engine == 'default' ) {
$termID = get_queried_object_id(); // determine which category we're viewing
// get the IDs of all the posts in this category
$args = array( 'category' => $termID, 'fields' => 'ids' );
$ids = get_posts( $args );
return $ids;
add_filter( 'searchwp_include', 'mySearchIncludeIds', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment