Last active
March 8, 2019 15:03
-
-
Save jchristopher/7491200 to your computer and use it in GitHub Desktop.
Limit SearchWP results to a single category
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 searchwp_include_only_category( $ids, $engine, $terms ) { | |
// Limit to category 10 | |
$categoryID = 10; | |
// Retrieve the IDs of all the posts in this category | |
$args = array( | |
'category' => $categoryID, | |
'fields' => 'ids', | |
'nopaging' => true, | |
); | |
$ids = get_posts( $args ); | |
return empty( $ids ) ? array( 0 ) : $ids; | |
} | |
add_filter( 'searchwp_include', 'searchwp_include_only_category', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment