首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从WP_Query中排除类别

从WP_Query中排除类别
EN

Stack Overflow用户
提问于 2020-05-11 21:21:10
回答 1查看 18关注 0票数 0

我试图在一个自定义的"Class“分类的归档页面上显示一个有特色的帖子,并且想要排除带有"work”和"extra“的类别中的帖子。下面并不排除这些类别:

代码语言:javascript
复制
$class = get_queried_object(); // Get the current class
$current_class = $class->term_id; //Get the current class ID
$extras_cat = get_cat_ID( 'extra' );
$class_work_cat = get_cat_ID( 'work' );

$args = array(
      'tax_query' => array(
        array(
          'taxonomy' => 'filmbites_class',
          'field'    => 'term_id',
          'terms'    => $current_class,
        ),
      ),
      'category__not_in' => array( $extras_cat, $class_work_cat ),
      'posts_per_page' => 1
    );

$posts= new WP_Query($args);

if($posts->have_posts()) :
  while($posts->have_posts()) :
      $posts->the_post();
      $featured_post = get_the_ID(); //get the ID of the post to be featured
    endwhile;
endif;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-11 21:37:15

我错误地使用了get_cat_ID()函数。使用插件而不是类别名称。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61730743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档