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

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

<div class="row">
<div class="all-shorts-container">
  $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();     
          <p><?php the_content(); ?></p>
      <footer class="short-rating-footer">
                <?php if(function_exists('the_ratings')) { the_ratings(); } ?>
    <?php endwhile; ?>
    <!-- end of the loop -->

    <!-- pagination here -->
 <!-- pagination here -->
      if (function_exists(custom_pagination)) {
<?php wp_reset_postdata(); ?>
<?php else:  ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
  <?php endif; ?>
<?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.


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.