Created
March 2, 2021 13:21
-
-
Save jchristopher/bb80477e899b232f0b42ea27df0d782f to your computer and use it in GitHub Desktop.
Limit SearchWP Native/Default results to Category that has 'foobar' slug
This file contains hidden or 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