[英]How do I use a tax_query and a meta_query in wordpress succesfully?
This is the code I am using:这是我正在使用的代码:
$results = array(
'post_type' => 'score',
'tax_query' => array(
array(
'taxonomy' => 'competitions',
'field' => 'slug',
'terms' => $tax->slug,
'compare' => '='
)
),
'meta_query' => array(
array(
'numberposts' => -1,
'post_type' => 'score',
'meta_key' => 'horse_name',
'meta_value' => $horsename,
'compare' => 'LIKE'
)
)
);
// query
$the_query = new WP_Query($results);
The problem is I can't work out how to make a Boolean AND expression so that both the taxonomy and the custom field should match before returning a post.问题是我不知道如何制作 Boolean AND 表达式,以便在返回帖子之前分类和自定义字段都应该匹配。
I revised your code.我修改了你的代码。 check below code.
检查下面的代码。
$results = array(
'post_type' => 'score',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'competitions',
'field' => 'slug',
'terms' => $tax->slug,
'compare' => '='
)
),
'meta_query' => array(
array(
'meta_key' => 'horse_name',
'meta_value' => $horsename,
'compare' => 'LIKE'
)
)
);
// query
$the_query = new WP_Query( $results );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.