0

I need to get all posts created by a specific author. For example, all the posts created by author 'test'. For each post I need the post title, description and featured image. Can anyone help?

if(isset($authors) && !empty($authors))
{
    echo "<ul>";
    foreach($authors as $author)
    {
        $posts = get_posts(array('test'=>$author->ID));
    }
}
tomhuckle
  • 25
  • 3

2 Answers2

0

You can do it something like this

$args = array(
'author_name' => 'test', // Replace 'test' with the actual author name
'posts_per_page' => -1 // -1 means retrieve all posts
);

$query = new WP_Query($args);

 if ($query->have_posts()) {
  while ($query->have_posts()) {
     $query->the_post();
     $post_title = get_the_title();
     $post_description = get_the_excerpt();
     $post_featured_image = get_the_post_thumbnail_url();
    
     // Output the post information as needed
     echo '<h2>' . $post_title . '</h2>';
     echo '<p>' . $post_description . '</p>';
     echo '<img src="' . $post_featured_image . '" alt="' . $post_title . '">';
    }
 }
wp_reset_postdata();
mehmood khan
  • 497
  • 1
  • 7
  • 20
0

Get get_current_user_id() or enter the user id returns the users and finally get particular author post

$user_id = get_current_user_id();  // or Enter the user id

$args=array(
    'post_type' => 'POSTTYPE',
    'post_status' => 'published',
    'posts_per_page' => 1,
    'author' => $user_id
);                       

$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); 
    the_title();
endwhile;