• Hello.
    How to display all posts by an author where he is the main author and co-author? On the author page.

    Му code

    
    <?php
    		get_header();
    		get_coauthors( $post_id );
    		$page = get_query_var('paged') ? get_query_var('paged') : 1;
        $page_offset = ($page-1) * 8;
        $authors = get_queried_object()->ID;
        $author_id = wp_list_pluck( get_coauthors( $post_id ), 'ID');
    		$coauthor_id = join(', ', $author_id);
    ?>
    
                <?php
                            
                            $postslist = get_posts( array(
                            'posts_per_page' => 10,
                            'offset' => $page_offset,
                            'author__in'    => $authors,
                            'orderby'     => 'date',
                            'order'       => 'DESC',
                            'post_type'   => 'post') );		
    					
    									  ?>
                        <?php foreach ($postslist as $post) : setup_postdata($post); ?>
    
                       
                            <div class="article_image">
                                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'article_arhive' ); ?></a>
                            </div>
                  
                        <?php endforeach; ?>
                        <?php wp_reset_postdata() ?>
    
    
    • This topic was modified 4 years, 1 month ago by fedorvs.
Viewing 2 replies - 1 through 2 (of 2 total)
  • $posts = new WP_Query( array(
      'author'  => get_queried_object_id(),
      'orderby' => 'date',
      'order'   => 'DESC',
    ) );
    
    if ( $posts->have_posts() ) :
      while ( $posts->have_posts() ) : $posts->the_post();
      ?>
    
      <div class="entry-summary">
        <figure class="post-thumbnail">
          <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'article_arhive' ); ?></a>
        </figure>
      </div>
    
      <?php
      endwhile;
      wp_reset_postdata();
    endif;
    

    I can’t edit or delete the previous reply. I made an error in the query args on the the author key. That is for standard user.

    if ( is_author() )
      $post_id = get_queried_object_id();
    
    $coauthors = get_coauthors( $post_id );
    if ( ! $coauthors ) return;
    
    foreach( $coauthors as $coauthor ) {
    
      $posts = new WP_Query( array(
          'orderby'   => 'date',
          'order'     => 'DESC',
          'tax_query' => array( array(
              'taxonomy' => 'author',
              'field'    => 'name',
              'terms'    => $coauthor->user_nicename,
          ) )
        ) );
    
      if ( ! $posts->have_posts() ) continue;
    
      while ( $posts->have_posts() ) : $posts->the_post();
      ?>
    
      <div class="entry-summary">
        <figure class="post-thumbnail">
          <a href="<?php the_permalink(); ?>">
          <?php the_post_thumbnail( 'article_archive' ); ?>
          </a>
        </figure>
      </div>
    
      <?php
      endwhile;
      wp_reset_postdata();
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show all posts by the author, where he is the main author and co-author’ is closed to new replies.