我试图从 WordPress 获取 5 个精选帖子,为了实现这个目标,我已经抵消了 5 个最近的帖子。我成功获取了帖子 id 和图像。但我未能获得每个帖子的描述。我尝试了下面的代码,但它只给了我 1 个帖子描述,而不是全部 5 个。
$my_posts = get_posts(array('numberposts' => 5,
'offset' => 5,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'));
foreach($my_posts as $post) {
$data[] =
array(
"id" => $post->ID,
"title" => $post->post_title,
"image" => get_the_post_thumbnail($post->ID),
// "content" =>$post['post_excerpt']
"content" => apply_filters('the_content', $post->post_content)
);
}
最佳答案
您将在循环中获得描述the_content()
函数。有关此功能的更多信息请访问 this页面
对于标题,您可以将 the_excerpt()
函数与循环结合使用
关于php - 如何获取wordpress帖子的描述和标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24250021/