【问题标题】:Display the posts only if both the categories exist仅当两个类别都存在时才显示帖子
【发布时间】:2018-04-12 15:01:15
【问题描述】:

仅当两个类别都存在时才显示帖子。

https://codex.wordpress.org/Class_Reference/WP_Meta_Query

我们如何才能只获取两个类别出口的帖子列表?

bartags = 26,27

if (isset($_POST['bartags']) && !empty($_POST['bartags'])):
        $tax_query[] = array(
            array(
                'taxonomy' => 'bar_tag',
                'terms' => explode(',',$_POST['bartags']),
                'compare'=>'IN', // what's use here? 
            )
        );
    endif;

【问题讨论】:

  • 你能把你的问题解释清楚吗?是否仅在两个类别都存在时才显示帖子?
  • 是的,我们只需要同时发布两个类别的出口

标签: mysql wordpress customization


【解决方案1】:
if (isset($_POST['bartags']) && !empty($_POST['bartags'])):
        $tax_query[] = array(
            array(
                'taxonomy' => 'bar_tag',
                'terms' => explode(',',$_POST['bartags']),
                'operator' => 'AND',
            )
        );
    endif;

这一个使用 'operator' => 'AND' 修复,它没有在文档上定义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 2020-05-06
    • 1970-01-01
    相关资源
    最近更新 更多