如何获得Sticky帖子和特定类别帖子的帖子ID?

时间:2016-04-12 12:39:48

标签: php wordpress

我正在使用此代码获取属于“特色”类别的帖子的ID。但我可以使用相同的查询检索那些也很粘的帖子吗?

$post_ids = get_posts(array(
  'numberposts'   => 8, 
  'category_name'    => 'featured',
  'orderby'          => 'date',
  'post_type'        => 'post',
  'fields'        => 'ids'
));  

现在我使用两个查询来获得所需的结果,但我认为有更好的方法可以做到这一点:

  //get featured ids
  $post_ids = get_posts(array(
     'numberposts'   => 5, 
     'category_name'    => 'featured',
     'orderby'          => 'date',
     'post_type'        => 'post',
     'fields'        => 'ids'
  )); 
  //get sticky id
  $sticky_post_ids = get_posts(array(
     'numberposts'   => '1', 
     'orderby'          => 'date',
     'post_type'        => 'post',
     'fields'        => 'ids'
     'post__in'     => get_option('sticky_posts')
  )); 

0 个答案:

没有答案