Show Co-Authored posts on Authors page

by user3786081   Last Updated September 09, 2018 18:08 PM

i'm using ACF for Co Authored posts. I want to show all the posts, which is an author also assigned as Co-Author.

Also, i'm doing this with pre_get_posts filter. I am able to get all the post id's of co-authored posts.

So, my query contains all the id's that i need. But when i want to show them with a simple while query, wordpress skips that posts, which author is not the main Author.

Is there any workarounds for this?

Thanks.

    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
      );
      if (get_query_var('paged')):
        $paged = get_query_var('paged');
      elseif (get_query_var('page')):
        $paged = get_query_var('page');
      else:
        $paged = 1;
      endif;

      $query->set('post_type', 'post');
      $query->set('paged', $paged);
      $query->set('post__in', $postIDs);
      $query->set('orderby', 'date');
      $query->set('order', 'DESC');
    endif;

Template:

    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;
Tags : pre-get-posts


Related Questions


Display only one post each WEEK

Updated April 06, 2015 17:03 PM


How to get post content by calling ajax?

Updated March 12, 2018 14:08 PM


How to translate acf repeater code to wordpress post type

Updated September 07, 2017 15:08 PM