0

我有一个名为“portcat”的自定义帖子类型,我想从页面中排除一个 portcat 类别(“天气”- 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'] 
                        ) 
                    );
            }
4

1 回答 1

0

来自 wordpress 法典:

排除属于类别的帖子

显示来自 post-type 的所有帖子,除了来自自定义术语的帖子:

$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
            ),
       )
    );
于 2013-05-06T10:12:50.083 回答