Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created February 8, 2022 13:52
Show Gist options
  • Save searchwpgists/da0d1621810c1b4e9142faf2016bc5ba to your computer and use it in GitHub Desktop.
Save searchwpgists/da0d1621810c1b4e9142faf2016bc5ba to your computer and use it in GitHub Desktop.
Limit SearchWP Native/Default results to Category that has 'foobar' slug
<?php
// Limit SearchWP Native/Default results to Category that has 'foobar' slug.
add_filter( 'searchwp\native\args', function( $args, $query ) {
if ( ! isset( $args['tax_query'] ) || ! is_array( $args['tax_query'] ) ) {
$args['tax_query'] = [];
}
$args['tax_query'][] = [
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'foobar',
];
return $args;
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment