在作者页面上显示共同撰写的帖子

时间:2018-09-10 08:48:26

标签: wordpress

我正在使用ACF作为共同撰写的帖子。我想显示所有帖子,这是一位也被指定为共同作者的作者。

此外,我正在使用pre_get_posts过滤器进行此操作。我可以获取所有共同撰写帖子的帖子ID。

因此,我的查询包含了我需要的所有ID。但是,当我想通过简单的while查询显示它们时,wordpress会跳过该帖子,该作者不是主要的Author。

有没有解决方法?

谢谢。

if ($query->is_author() && $query->is_main_query()):
  $author = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
  $authorPostIDs = self::getAuthorsPostIDs($author->ID);
  $coAuthorPostIDs = self::getCoAuthorsPostsIDs($author->ID);
  $postIDs = array_unique(
    array_merge($coAuthorPostIDs, $authorPostIDs), SORT_REGULAR
  );

  $query->set('post__in', $postIDs);

endif;

模板:

while (have_posts()) :
     the_post();
     Theme::setTemplateVariables(['show_excerpt' => FALSE]);
     get_template_part('templates/article', get_post_type() !== 'post' ? get_post_type() : get_post_format());
endwhile;

0 个答案:

没有答案
相关问题