duanma8207
duanma8207
2015-04-27 08:06
浏览 37
已采纳

我无法从wordpress中的自定义帖子类型的归档页面中排除自定义分类法

I have written a piece of code to build a paginated archive page for a custom post type. I cannot exclude a certain custom taxonomy. can anyone help, please?

$temp = $wp_query;     
$wp_query = null; 
$wp_query = new WP_Query(); 
$wp_query->query('showposts=30&post_type=my_custom_post_type'.'&paged='.$paged);

图片转代码服务由CSDN问答提供 功能建议

我编写了一段代码来构建自定义帖子类型的分页存档页面。 我不能排除某种自定义分类。 有人可以帮忙吗?

  $ temp = $ wp_query;  
 $ wp_query = null;  
 $ wp_query = new WP_Query();  
 $ wp_query-> query('showposts = 30& post_type = my_custom_post_type'。'& paged ='。$ paged); 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxiaoxiao1983
    dongxiaoxiao1983 2015-04-27 08:49
    已采纳

    You have to include the tax_query parameter in query array like here:

      $query_args = array(
      'showposts' => 30,
      'paged' => $paged,
      'post_type' => 'my_custom_post_type',       
      'tax_query'   => array(
                array(
                    'taxonomy'  => 'custom-taxonomy-name',
                    'field'     => 'slug',
                    'terms'     => 'slug-name', 
                    'operator'  => 'NOT IN')
                    ),
               )
     );
    
    $wp_query->query($query_args);
    

    Please write your custom taxonomy name at the place of 'custom-taxonomy-name' and taxonomy slug name at the place of 'slug-name'

    点赞 评论

相关推荐