Wordpress 排除查询上的类别\u发布自定义分类法

Wordpress 排除查询上的类别\u发布自定义分类法,wordpress,Wordpress,我需要从显示帖子中排除一个类别。 我注册了分类法:公文包类别 并在公文包类别下添加了一个类别:附件(类别ID 19) 如何将附件类别中的帖子排除在外? 我试过:'category'=>-19,但没用 这是我的密码: <?php $args=array( 'post_type' => 'items', 'post_status' =

我需要从显示帖子中排除一个类别。 我注册了分类法:公文包类别 并在公文包类别下添加了一个类别:附件(类别ID 19)

如何将附件类别中的帖子排除在外? 我试过:
'category'=>-19,
但没用 这是我的密码:

        <?php
                $args=array(
                    'post_type'         => 'items',
                    'post_status'       => 'publish',
                    'showposts'         => intval( get_anolox_option_by('an_homep_count', 3) ),
                    'caller_get_posts'  => 1,
                    'category'          => -19,
                    'paged'             => $paged,
                );
                query_posts($args);

                $end = array(3,6,9,12,15,18,21,24,27,30,33,36,39,42,45);

                $i = 0;
                while (have_posts()): the_post();
                global $post;
                $i++;
            ?>

    MY CODE HERE, NO NEED TO SHOW SINCE IT'S VERY LONG



            <?php endwhile; ?>          
            <?php wp_reset_query(); ?>

我的代码在这里,不需要显示,因为它很长
编辑//我尝试了这段代码,但仍然不起作用:

    <?php
                $args=array(
                    'post_type'         => 'items',
                    'post_status'       => 'publish',
                    'showposts'         => intval( get_anolox_option_by('an_homep_count', 3) ),
                    'caller_get_posts'  => 1,

                    'paged'             => $paged,
                    'tax_query'          => array(
                        'taxonomy' => 'portfolio-category',
                        'terms' => 'accessories',
                        'field' => 'slug',
                        'operator' => 'NOT IN')
                );
                query_posts($args);

参数
category
用于内置类别分类法。像这样更改
$args
以引用自定义分类法:

$args=array(
    'post_type'          => 'items',
    'portfolio-category' => 'accessories',
    'post_status'        => 'publish',
    'showposts'          => intval( get_anolox_option_by('an_homep_count', 3)),
    'paged'              => $paged
);
这假设如下:

  • 您有一个名为
    items
    的自定义帖子类型
  • portfolio类别
    分类法已注册到它
  • 附件
    添加到
    组合类别
    分类中
  • 更新:哎哟…迟到了。要回答OP的实际问题,即如何排除
    附件
    组合类别(而不是像上面那样包括它),您可以使用参数。排除附件的代码如下所示:

    $args=array(
        'post_type'          => 'items'
        'post_status'        => 'publish',
        'showposts'          => intval( get_anolox_option_by('an_homep_count', 3)),
        'paged'              => $paged,
        'tax_query'          => array(
            'taxonomy' => 'portfolio-category',
            'terms' => 19,      
            'field' => 'id',
            'operator' => 'NOT IN' 
        )
    );
    

    问题似乎是一层嵌套。试着改变

        $args=array(
        'post_type'          => 'items'
        'post_status'        => 'publish',
        'showposts'          => intval( get_anolox_option_by('an_homep_count', 3)),
        'paged'              => $paged,
        'tax_query'          => array(
            'taxonomy' => 'portfolio-category',
            'terms' => 19,      
            'field' => 'id',
            'operator' => 'NOT IN' 
        )
    );
    
    致:

    这对我有用-/

    $args = array(
            'post_type'=>'items',
            'order'=>'ASC',
            'posts_per_page'=>3
            'tax_query' => array(
                array(
                'taxonomy' => 'portfolio-category',
                'field' => 'id',
                'terms' => 19,
                'operator' => 'NOT IN',
                ),
            )
    ));
    query_posts($args);
    
    items=自定义帖子类型

    公文包类别=我的自定义分类法

    for multiple category exclude use  'terms' => array( '19,20' ),
    

    我试过了,但并没有排除它只显示附件类别中的帖子,我想要的是排除“附件”类别中的帖子。我试过那个代码,但没用,它仍然显示附件类别中的帖子。。我用你给我的代码更新了我的帖子,我已经做了另一次更新,可能会解决这个问题。现在查询直接检查自定义分类法的
    id
    ,而不是
    slug
    。仍然不起作用..:(以防万一,这里是自定义的帖子类型代码:实际页面:我在其中放置了循环,我不确定为什么它不起作用,从我对您提供的代码的理解来看,它应该起作用。boo…对不起,我完全没有主意了:(正如clifgriffin所说,问题是关于数组嵌套。这应该是绿色的答案。它刚才对我来说非常有效,挽救了这一天!
    for multiple category exclude use  'terms' => array( '19,20' ),