正如T31所说,您不能使用WP\\u Query directy来实现这一点。
您可以尝试使用“posts\\u子句”过滤器来修改WP\\u查询生成的各个SQL子句,但无论您如何操作,这都将非常棘手。
相反,替换整个SQL查询可能更容易。您可以使用get\\u tax\\u sql()处理分类部分(未测试):
function my_posts_request( $old_query, $wp_query ) {
global $wpdb;
$ptypes = $wp_query->get(\'post_type\');
if ( \'page\' != $ptypes[2][\'post_type\'] )
return $old_query; // This is not the WP_Query you are looking for
// Do the conditional tax_query
$tax_query = array(
array(
\'taxonomy\' => \'options\',
\'terms\' => array( \'set-as-news-item\' ),
\'field\' => \'slug\',
)
);
$clauses = get_tax_sql( $tax_query, $wpdb->posts, \'ID\' );
$join = "FROM $wpdb->posts {$clauses[\'join\']}";
$where = "WHERE (
post_type = \'aucc_publication\' OR
post_type = \'aucc_media\' OR
(post_type = \'page\' {$clauses[\'where\']})
)";
// Do the other tax query
$tax_query = array(
array(
\'taxonomy\' => \'section\',
\'terms\' => array( \'programs-and-services\' ),
\'field\' => \'slug\',
),
array(
\'taxonomy\' => \'regions\',
\'terms\' => array( \'ghana\' ),
\'field\' => \'slug\',
)
);
$clauses = get_tax_sql( $tax_query, $wpdb->posts, \'ID\' );
$join .= $clauses[\'join\'];
$where .= $clauses[\'where\'];
return "SELECT $wpdb->posts.* $join $where ORDER BY post_date LIMIT 10";
}
add_filter( \'posts_request\', \'my_posts_request\' );
您仍然需要处理分页等问题。看看WP\\u Query是如何做到这一点的。