Support » Plugin: Co-Authors Plus » Can’t echo all coauthors in loop

  • fromagerflorian

    (@fromagerflorian)


    Hello,

    I did a summary of different pages with a while loop and call children of pages when they have some with a foreach, and I call the coauthors for each of them as I did in the single pages, but when there is more than one author, I just can see the first of them :

    <ul id="home-slider-nav">
    
          <?php $my_query = new WP_Query($args);
                if ($my_query->have_posts()) {
                   while ($my_query->have_posts()) : $my_query->the_post();
                     $posts = get_field('connexe_article_new');
          ?>
    
             <li class="separator-h">
                
                <h5 class="separator-h"><?php if(!$posts): ?><a href="<?php the_permalink() ?>"><?php the_title() ?></a><?php else: ?><?php the_title() ?><?php endif ?></h5>
    
                <?php if($posts):
                      $total = count($posts); ?>
                <ol>
                   <?php foreach($posts as $key=>$post):
                         setup_postdata($post); 
                   ?>
                   <li<?php if(($key+1)!=$total){ echo ' class="separator-h"';}elseif(($key+1)==$total){ echo ' style="padding:0"';} ?>>
                      <h6 class="no-c"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
                      <p class="cat">par <?php echo coauthors(', ',', ', null,null,false); ?></p>
                   </li>
    
                   <?php endforeach; ?>
                </ol>
    
             <?php else: ?>
                <div>
                <?php echo'<p class="separator-h no-c cat"> par <span>'.coauthors(', ',', ', null,null,false).'</span></p>'; ?>
                   <p class="cat"><b><?php echo get_first_category(); ?></b><span class="excerpt separator-l"><?php echo get_the_excerpt(); ?></span></p>
                </div>
    
             <?php wp_reset_postdata();
                   endif;
             ?>
          </li>
    
          <?php endwhile;
                wp_reset_postdata();  // Restore global post data stomped by the_post().
             } // if ($my_query)
          ?>
          </ul>

    The page I need help with: [log in to see the link]

  • The topic ‘Can’t echo all coauthors in loop’ is closed to new replies.