Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created October 2, 2013 18:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/6798262 to your computer and use it in GitHub Desktop.
Save jchristopher/6798262 to your computer and use it in GitHub Desktop.
SearchWP snippet to limit results to the current category page being viewed
<?php
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