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

Display the posts only if both the categories exist

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

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;
if (isset($_POST['bartags']) && !empty($_POST['bartags'])):
        $tax_query[] = array(
            array(
                'taxonomy' => 'bar_tag',
                'terms' => explode(',',$_POST['bartags']),
                'operator' => 'AND',
            )
        );
    endif;

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