Created
March 2, 2021 13:11
-
-
Save jchristopher/373f9f61ebea9db5271ccd24c6b2dea1 to your computer and use it in GitHub Desktop.
Limit SearchWP results to Category that has 'foobar' slug
This file contains hidden or 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
Hello, is there anyway to limit search results to 100 posts | 10 per page?