显示来自两个或更多自定义分类术语的帖子

时间:2013-03-02 作者:Bhupendra Kunwar

我想显示提交了2个或更多自定义分类术语的帖子。例如,我想显示自定义帖子类型“分类”的帖子,并将其归档在Books和House terms下。

下面的代码显示了在术语中标记的帖子。我只想在两个术语中标记帖子:

$args = array(
    \'posts_per_page\' => 10,  // Number of posts per page
    \'post_type\' => \'classifieds\',   // Custom Post Type like Movies
    \'tax_query\' => array(
        array(
            \'taxonomy\' => \'classifieds_tags\',   //Custom Taxonomy Name like Genre
            \'field\' => \'slug\',
            \'terms\' => array(
                \'books\',    //Tags or Categories like Drama or Comedy
                \'houses\'
            )
        )
    )
);

2 个回复
SO网友:David

您需要将两个税务查询与和结合起来AND 关系:

$args = array(
    \'posts_per_page\' => 10,  // Number of posts per page
    \'post_type\' => \'classifieds\',   // Custom Post Type like Movies
    \'tax_query\' => array(
        \'relation\' => \'AND\'
        array(
            \'taxonomy\' => \'classifieds_tags\',   //Custom Taxonomy Name like Genre
            \'field\' => \'slug\',
            \'terms\' => array(
                \'books\' //Tags or Categories like Drama or Comedy
            )
        ),
        array(
            \'taxonomy\' => \'classifieds_tags\',   //Custom Taxonomy Name like Genre
            \'field\' => \'slug\',
            \'terms\' => array(
                \'houses\'
            )
        ),
    )
);

SO网友:Simon

我认为您需要添加relation参数:

$args = array(
    \'posts_per_page\' => 10,  // Number of posts per page
    \'post_type\' => \'classifieds\',   // Custom Post Type like Movies
    \'tax_query\' => array(
        array(
            \'taxonomy\' => \'classifieds_tags\',   //Custom Taxonomy Name like Genre
            \'field\' => \'slug\',
            \'relation\' => \'AND\',
            \'terms\' => array(
                \'books\',    //Tags or Categories like Drama or Comedy
                \'houses\'
            )
        )
    )
);

结束

相关推荐

encoded search terms with %20

<form class=\"search-form\" action=\"<?php echo home_url( \'/suche/\' ); ?>\" method=\"get\"> <input type=\"text\" name=\"s\" class=\"s\" value=\"<?php the_search_query(); ?>\" /> 这是我的searchform.php 样板你知道为什么在搜索例如“