Wordpress query_posts多个数组?

问题描述:

Does anyone know if it is possible to have multiple arrays within query_posts if so how?

I'm looking to query posts that are in category 1 & 2. But also posts that are in 1 & 3 and 1 & 4.

So the posts MUST be in category 1 as well as one of the other categories.

So the category__and would be where I've started which allows me to query posts both in 1 & 2 but how would I then progress to add the others 3,4 etc? as adding them 1,2,3,4,5 will only show posts in all 5 categories correct?

Here is what I have so far:

<?php                                   
    query_posts( 
        array( 'category__and' => array(1,2), 
        'posts_per_page' => 5, 
        'orderby' => 'date', 
              ) );
    while (have_posts()) : the_post();  
?>

Is it possible to put an array of arrays to perform what I have asked?

有人知道在query_posts中是否可以有多个数组,如果是这样的话? p> \ n

我想查询1类和1类的帖子 2.还有1&amp; 1中的帖子。 3和1&amp; 4。 p>

所以帖子必须在第1类以及其他类别之一。 p>

所以类别___将是我所在的地方 开始,它允许我查询1和1中的帖子 2但是我如何进步添加其他3,4等? 添加它们1,2,3,4,5只会显示所有5个类别的帖子是否正确? p>

这是我到目前为止的内容: p> &lt;?php query_posts( array('category__and'=&gt; array(1,2), 'stovers_per_page'=&gt; 5, 'orderby'=&gt;'date ', )); while(have_posts()):the_post(); ?&gt; code> pre>

是否可以放置一个数组数组来执行我的要求? p> div>

This should be possible with the tax_query parameter.

query_posts(
    array(
        posts_per_page => 5,
        tax_query => array(
            relation => 'OR',
            array(
                'taxonomy' => 'category',
                'operator' => 'IN',
                'field' => 'id',
                'terms' => array( 1, 2 ),
            ),
            array(
                'taxonomy' => 'category',
                'operator' => 'IN',
                'field' => 'id',
                'terms' => array( 1, 3 ),
            ),
            array(
                'taxonomy' => 'category',
                'operator' => 'IN',
                'field' => 'id',
                'terms' => array( 1, 4 ),
            ),
        ),
    )
);

See the documentation for any additional details: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters