【问题标题】:WP_Query Custom Post type, with specific categoriesWP_Query 自定义帖子类型,具有特定类别
【发布时间】:2015-05-03 17:38:09
【问题描述】:

我正在尝试制作一个 WP_Query,它将循环到自定义帖子类型并仅在特定类别中为我提供结果。

我的最终查询字符串的 print_r 是

(
    [post_type] => portfolio
    [post_status] => publish
    [paged] => 1
    [posts_per_page] => 60
    [tax_query] => Array
        (
            [0] => Array
                (
                    [taxonomy] => portfolio_category
                    [field] => term_id
                    [terms] => Array
                        (
                            [0] => 229
                            [1] => 219
                        )

                    [operator] => IN
                )

        )

)

这很好用,但它显示所有类别为 229 和 219 的帖子。我不想显示,我想显示同时在 229 和 219 中的帖子。我该怎么做?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    将您的 tax_query 运算符更改为 AND

    operator (string) - 要测试的运算符。可能的值为“IN”(默认)、“NOT IN”、“AND”。 Source: Wordpress Documentation

    例如:

    $args = array(
        'post_type' => 'portfolio',
        'tax_query' => array(
            array(
                'taxonomy' => 'portfolio_category',
                'field'    => 'term_id',
                'terms'    => array( 229, 219 ),
                'operator' => 'AND',
            ),
        ),
    );
    
    $query = new WP_Query( $args );
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多