Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created March 2, 2021 13:11
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/373f9f61ebea9db5271ccd24c6b2dea1 to your computer and use it in GitHub Desktop.
Save jchristopher/373f9f61ebea9db5271ccd24c6b2dea1 to your computer and use it in GitHub Desktop.
Limit SearchWP results to Category that has 'foobar' slug
<?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 );
@phamquangbaoplus
Copy link

Hello, is there anyway to limit search results to 100 posts | 10 per page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment