-
-
Save searchwpgists/5ed26c65f20f209177f6b2b9afd39d85 to your computer and use it in GitHub Desktop.
Limit SearchWP results to Category that has 'foobar' slug
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 | |
// Limit SearchWP results to Category that has 'foobar' slug. | |
$search = new \SWP_Query( [ | |
's' => 'coffee', // Search string. | |
'tax_query' => [ [ | |
'taxonomy' => 'category', | |
'field' => 'slug', | |
'terms' => 'foobar', | |
] ], | |
] ); | |
// Print all results. | |
print_r( $search->posts ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment