Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created March 2, 2021 13:21
Show Gist options
  • Save jchristopher/bb80477e899b232f0b42ea27df0d782f to your computer and use it in GitHub Desktop.
Save jchristopher/bb80477e899b232f0b42ea27df0d782f 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