如何在 tax_query 和 meta_query Wordpress 中给出 OR 关系 [英] How to give OR relation in tax_query and meta_query Wordpress

查看:28
本文介绍了如何在 tax_query 和 meta_query Wordpress 中给出 OR 关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给出 tax_querymeta_query 之间的 OR 关系:

I want give OR relation between tax_query and meta_query:

$post_args = array('post_type' => 'post',
    'order'     => 'DESC',
    'meta_query' => array(
     'relation'  => 'OR',
          array(
            'key' => 'client_segment',
            'value' =>$client ,
            'compare' => 'IN',
          ),
          array(
                'key'  => 'filtered_date',
                'value'=> array($start_date, $end_date),
                'compare'   => 'BETWEEN'
            )
        ),
        'tax_query' => array(
        'relation' => 'OR',
        array(
            'taxonomy'  => 'category',
            'field'     => 'id',
            'terms'     => $term_id,
            'operator'  => 'IN')

            ),
);

$posts = new WP_Query($post_args);  

我的代码有什么问题?

推荐答案

没有办法在两个查询之间给出 OR 关系,但是你可以做两个单独的查询然后合并它们的结果.

There is no way to give OR relation between two queries, but what you can do to make two separate queries and then merge the results of them.

因为基本上你需要这两个查询的结果.

Because basically you need results of both of these queries.

你可以找到解决方案如何合并这篇文章中的 2 个查询

这篇关于如何在 tax_query 和 meta_query Wordpress 中给出 OR 关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆