Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leobaiano/c7a6748a71e50984e25f to your computer and use it in GitHub Desktop.
Save leobaiano/c7a6748a71e50984e25f to your computer and use it in GitHub Desktop.
Filotro de busca WordPress com taxonomys
<?php
function filter_search( $query ) {
if ( !is_admin() && $query->is_main_query() && $query->is_search ) {
$tax_query = array(
array(
'taxonomy' => 'frutas',
'field' => 'slug',
'terms' => 'laranja'
),
array(
'taxonomy' => 'frutas',
'field' => 'slug',
'terms' => 'maca'
),
'relation' => 'AND'
);
$query->set( 'tax_query', $tax_query );
}
}
add_action ('pre_get_posts', 'filter_search' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment