我需要得到一个特定的作者创建的所有职位。例如,由作者'测试'创建的所有职位。对于每个职位,我需要职位的标题,描述和特色图像。有人能帮忙吗?
if(isset($authors) && !empty($authors)) { echo "<ul>"; foreach($authors as $author) { $posts = get_posts(array('test'=>$author->ID)); } }
lmvvr0a81#
你可以这样做
$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();
1条答案
按热度按时间lmvvr0a81#
你可以这样做