0

I am archiving all the posts from particular custom post type on a page using the following code.

<?php
/*
Template Name: List-all-shorts
*/
?>
<?php get_header(); ?>

<div class="row">
<div class="all-shorts-container">
<h2>Shorts</h2>
<?php 
  $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$author = the_author();
  $custom_args = array(
      'post_type' => 'news',
      'posts_per_page' => 10,
      'paged' => $paged,
      'author' => $author
    );
  $custom_query = new WP_Query( $custom_args ); ?>
<?php if ( $custom_query->have_posts() ) : ?>
    <!-- the loop -->
    <?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
    <div class="single-shorts-container">
      <article class="short-box">
        <div class="short-content">
       <div class="short-meta-box">
        <div class="short-author-meta-img"> <?php   the_author_image();     
        ?>
       </div>
          <p><?php the_content(); ?></p>
        </div>
      </article>
      <footer class="short-rating-footer">
                <?php if(function_exists('the_ratings')) { the_ratings(); } ?>
    </footer>
    </div>
    <?php endwhile; ?>
    <!-- end of the loop -->

    <!-- pagination here -->
 <!-- pagination here -->
    <?php
      if (function_exists(custom_pagination)) {
        custom_pagination($custom_query->max_num_pages,"",$paged);
      }
    ?>
<?php wp_reset_postdata(); ?>
<?php else:  ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
  <?php endif; ?>
    </div>
</div>
<?php get_footer(); ?>

The above code displays all the posts as I wanted. I am trying to show author image of all the individual posts accordingly. I tried using

<?php the_author(); ?> and <?php  echo get_avatar( get_the_author_email(), '32' ); ?>

and many other things. But I am getting the image of the author of the page. I am quite not sure where I went wrong.

Also, I am able to get the author name and author profile link for the posts. Any help would be highly appreciated.

0

Looks like you use a page to get the custom post type posts? If you have a custom post type cars you should create a cars-archive.php as template and the url /cars should show your custom post type cars. You created a page to show the post type that's possible but not the common way.

So copy your code into yourposttype-archive.php and go after that to yoursiteurl.com/yourposttype that should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.