You are fighting with the post global
s, like $post
, and are not getting them set correctly. Create a proper Loop using WP_Query
and use Core template tags where possible and the problem will go away.
$authors_posts = new WP_Query(
array(
'author' => 7,
'posts_per_page' => 6,
'post__not_in' => array( $post->ID )
)
);
$output="<ul>";
while ($authors_posts->have_posts()) {
$authors_posts->the_post();
// Build a comma separated categories list
// You can customize as needed
$categories_string = get_the_category_list();
$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'related-author' );
$output .= '<li>
<a class="title" href="' . get_permalink() . '">
<strong>' . get_the_title() . '</strong>
<img src="'.$image[0].'">
</a>
<span>'.get_the_time('m.d.y').'</span> '.$categories_string.'
</li>';
}
wp_reset_postdata();
$output .= '</ul>';
Also, note that your code was far more complex than it needed to be and basically recreated, in limited form, Core functionality.