gpt4 book ai didi

How to Set relationship "OR" meta_query OR tax_query(如何设置关系“OR”META_QUERY或TAX_QUERY)

转载 作者:bug小助手 更新时间:2023-10-25 11:45:22 28 4
gpt4 key购买 nike



I'm trying to use WP_Query to create a query with both a meta_query element and tax_query element. The kicker is that I don't want to find the results where both conditions are met (and AND clause) I want to find the conditions where either one or the other are met (OR clause).

我正在尝试使用WP_QUERY来创建同时具有META_QUERY元素和TAX_QUERY元素的查询。关键是我不想找到同时满足两个条件的结果(AND AND子句),我想找到满足其中一个条件的条件(OR子句)。


$loop = new WP_Query( array( 
'post_type' => 'tickets',
'paged' => $paged,
'order' => $order,
'orderby' => $orderby,
'meta_query' => array(
array(
'key' => 'tps_email', // Use 'key' for author
'value' => '[email protected]', // Replace with the author ID you want to query
'compare' => 'LIKE', // Use '=' to match the author ID
),
),
'tax_query' => array(
array(
'taxonomy' => 'topic', // Replace with your custom taxonomy name
'field' => 'slug', // You can use 'id', 'slug', or 'name' depending on how you want to identify the term
'terms' => 'housekeeping', // Replace with the slug of the specific term you want to query
),
),
)
);



I accept outputs like this
enter image description here

我接受这样的输出


更多回答
优秀答案推荐

Here's how you can set up a "OR" relationship between meta_query and tax_query:

下面介绍如何在META_QUERY和TAX_QUERY之间设置“OR”关系:


$args = array(
'post_type' => 'tickets',
'paged' => $paged,
'order' => $order,
'tax_query' => array(
'relation' => 'OR', // Set the relationship to OR
array(
'taxonomy' => 'topic',
'field' => 'slug',
'terms' => 'housekeeping',
),
array(
'taxonomy' => 'your_taxonomy_2',
'field' => 'slug',
'terms' => 'term_slug_2',
),
),
'meta_query' => array(
'relation' => 'OR', // Set the relationship to OR
array(
'key' => 'tps_email',
'value' => '[email protected]',
'compare' => '='
),
array(
'key' => 'custom_field_2',
'value' => 'custom_value_2',
'compare' => '='
),
),
);

更多回答

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com