【问题标题】:Wordpress get posts not in custom taxonomy termWordpress 获取不在自定义分类术语中的帖子
【发布时间】:2014-01-29 13:57:30
【问题描述】:

以下代码应该获取自定义分类中没有特定术语的帖子。目前它仍然得到他们。是不是少了什么东西。

$args = array(
            'numberposts' => '3',
            'post__not_in' => $post_not_in,
            'tax_query' => array(
                'taxonomy' => 'topic',
                'terms' => 9,      
                'field' => 'id',
                'operator' => 'NOT IN'
            ) 
        ); 
        $extras = get_posts($args);

【问题讨论】:

    标签: wordpress custom-taxonomy notin


    【解决方案1】:

    重要提示: tax_query 接受一个税务查询参数数组的数组(它接受一个数组数组)

    ——Wordpress Codex on Taxonomy Parameters

    你试过了吗?

    $args = array(
        'numberposts' => '3',
        'post__not_in' => $post_not_in,
        'tax_query' => array(
            array(
                'taxonomy' => 'topic',
                'terms' => 9,      
                'field' => 'id',
                'operator' => 'NOT IN'
            )
        )
    ); 
    $extras = get_posts($args);
    

    【讨论】:

    • 那么如何获取没有指定分类的帖子呢? (即条款 => 空?)
    • @knutole 我不确定,但你应该试试this answer
    猜你喜欢
    • 2016-07-01
    • 2012-04-01
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 2012-11-25
    相关资源
    最近更新 更多