Created
October 2, 2013 18:25
-
-
Save jchristopher/6798262 to your computer and use it in GitHub Desktop.
SearchWP snippet to limit results to the current category page being viewed
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 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