排除自定义帖子类型中的一个类别

时间:2013-05-06 10:09:00

标签: php post categories

我有一个名为'portcat'的自定义帖子类型,我想从页面中排除一个portcat类别('weather' - ID为'5')。我可以在下面的代码中添加什么来排除它?

<?php
   $temp = $wp_query;
   $wp_query = null;
   $wp_query = new WP_Query();
                 $args = array(
                 'post_type' => 'port',
                 'paged' => $paged,
                 'posts_per_page' => get_theme_option("portfolio_work_count"),           
                 );


   if (isset($_GET['slug'])) {
     $args['tax_query']=array(
                         array(  
                          'taxonomy' => 'portcat',
                          'field' => 'slug',
                          'terms' => $_GET['slug'] 
                        ) 
                    );
            }

1 个答案:

答案 0 :(得分:0)

from wordpress codex :

排除属于类别的帖子

显示来自后期类型的所有帖子,但自定义术语中的帖子除外:

$query = new WP_Query(
    array(
      'post_type'   => 'port',  // only query post type
      'tax_query'   => array(
        array(
            'taxonomy'  => 'portcat',
            'field'     => 'slug',
            'terms'     => '$_GET['slug']',
            'operator'  => 'NOT IN') // seems that's what you're missing
            ),
       )
    );