我需要获取特定作者创建的所有帖子。例如,作者“test”创建的所有帖子。对于每个帖子,我都需要帖子标题、描述和特色图片。谁能帮忙?
if(isset($authors) && !empty($authors))
{
echo "<ul>";
foreach($authors as $author)
{
$posts = get_posts(array('test'=>$author->ID));
}
}
你可以这样做
$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();