WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This has been bugging me for ages and can't quite get it working. I'm using the following code in my functions file to enable me to display posts created by the same author as the current single post.

function get_related_author_posts() {
global $authordata, $post;

$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 1, 'post_type' => 'artistblog' ) );

foreach ( $authors_posts as $authors_post ) {
    $output .= '<div class="artist-blog-thumb"><a href="' . get_permalink( $authors_post->ID ) . '">'. get_the_post_thumbnail( $authors_post->ID,'medium' ) .'</a></div><h3><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></h3>';


return $output;

This works nicely. However I also want to display the automatically trimmed excerpt for each post. I've tried various methods and none of them have quite worked.

Can anyone help with this please?

share|improve this question
up vote 1 down vote accepted

your code is not wrong. However, in my opinion, it would be better to handle the task in a slightly different way.


In your functions.php:

/* This function returns the related posts in an array of objects. You can set how many items you want retrieve.If not set, the number of items will be set to "1". */
function get_related_author_posts( $items = 1 ) {
  global $authordata, $post;
  $authors_posts = get_posts( 
      'author' => $authordata->ID, 
      'post__not_in' => array( $post->ID ), 
      'posts_per_page' => $items, 
      'post_type' => 'artistblog' 
  return $authors_posts;

In your template file:

  $related_posts = get_related_author_posts( 3 );
  foreach( $related_posts as $post ) : setup_postdata( $post ); ?>
  <div class="artist-blog-thumb">
    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'medium' ); ?></a>
  <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  <div class="excerpt">
    <p><?php the_excerpt(); ?></p>
<?php endforeach; wp_reset_postdata(); ?>

Let me know if you get stuck.

share|improve this answer
Thank you iEmanuele! Always seems so obvious when someone points it out to you. Your suggestion worked perfectly! Cheers D – user36987 Aug 28 '13 at 13:16
@user36987, you're welcome! – iEmanuele Aug 28 '13 at 13:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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