-
-
Save vishalkakadiya/b011db3b8b5aec8ee3b08216f1e6775d to your computer and use it in GitHub Desktop.
how to add a tax_query to pre_get_posts in wordpress
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 | |
add_action( 'pre_get_posts', array( $this,'function_pre_get_posts' ) ); | |
function function_pre_get_posts(){ | |
// you can't use the query->set here for tax_query | |
// as tax query has already been made | |
// so you need to need add youself to any | |
// existing tax query | |
$tax_query = array( | |
'taxonomy' => 'tax_name', | |
'field' => 'slug', | |
'terms' => 'term_name', | |
'operator'=> 'IN' ); | |
$query->tax_query->queries[] = $tax_query; | |
$query->query_vars['tax_query'] = $query->tax_query->queries; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment