0

In my author.php page, I'm wanting to create a link that sends the user to a list of all posts by that author. I thought this was a built in function of WordPress, but having trouble finding the function and its syntax.

the_author_posts_link() seems to just link back to the author page.

<div class="outerContainer longFormContainer">
   <div class="contentContainerNarrow longFormContent">

      <?php 
          $post_author_id = get_the_author_meta('ID');
      ?>

       <?php if( get_field('author_img', 'user_' . $post_author_id) ): ?>
          <img class="alignleft" src="<?php the_field('author_img', 'user_' . $post_author_id); ?>" width="200" alt="<?php the_author(); ?>" />
       <?php endif; ?>

       <?php
          if ( get_the_author_meta('description') ) : 
             echo '<p>';
             echo the_author_description();
             echo '</p>';
           endif;
        ?>

        <p>View all posts by <?php the_author_posts_link(); ?></p>
    </div>
</div>
1

the_author_posts_link() points precisely to your author.php template, and it's normally used in posts (inside the loop).

So to get the author's posts list, you have two options:

1) Show the author posts in the same author.php template, simply using the normal loop (because this is just the query loaded in this template). By the way, you have a nice example in the codex.

2) Generate a different template that shows only (as you want) the author's posts list, querying as follows:

$query = new WP_Query( array( 'author_name' => 'nicename' ) ); //author 'user_nicename'

Probably it will be a good point to load the nicename as a custom_query_var

Hope it helps!

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.