您可以随时使用posts_clauses
在其中筛选并添加对tax\\u查询的处理(您甚至不需要编写自己的SQL):
function filter_single_with_tax_queries( $clauses, $query ) {
global $wpdb;
if ( $query->is_singular ) {
$query->parse_tax_query( $query->query_vars );
$tax_clauses = $query->tax_query->get_sql( $wpdb->posts, \'ID\' );
$clauses[\'join\'] .= $tax_clauses[\'join\'];
$clauses[\'where\'] .= $tax_clauses[\'where\'];
}
return $parts;
}
add_action( \'posts_clauses\', \'filter_single_with_tax_queries\', 10, 2 );