-
-
Save searchwpgists/da0d1621810c1b4e9142faf2016bc5ba to your computer and use it in GitHub Desktop.
Limit SearchWP Native/Default results to Category that has 'foobar' slug
This file contains 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 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