是否排除“公文包”自定义类别?

时间:2013-05-07 作者:Sam

我有一个名为“portcat”的自定义帖子类型,我想从页面中排除一个portcat类别(“weather”-ID=\'5”)。我试过了\'category__not_in\' => array( 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 个回复
SO网友:Adam

请看一下这个例子;

$args = array(
    \'post_type\' => \'post\',
    \'tax_query\' => array(
        \'relation\' => \'AND\',
        array(
            \'taxonomy\' => \'movie_genre\',
            \'field\' => \'slug\',
            \'terms\' => array( \'action\', \'comedy\' )
        ),
        array(
            \'taxonomy\' => \'actor\',
            \'field\' => \'id\',
            \'terms\' => array( 103, 115, 206 ),
            \'operator\' => \'NOT IN\' //you must set the operator to NOT IN
        )
    )
);
$query = new WP_Query( $args );
更多详细信息,请参见法典中的WP\\U查询;

http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

结束

相关推荐

突出显示Function.php中的搜索结果

我在网上找到了这个函数。我已将其与函数分开放置在自定义函数文件中。php。function highlight_search_term($text){ if(is_search()){ $keys = implode(\'|\', explode(\' \', get_search_query())); $text = preg_replace(\'/(\' . $keys .\')/iu\', \'<span class=\"sear