Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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