試試這個
<?php
$args = array('post_type'=>'post',
'orderby'=>'post_date',
'post_status'=>'publish',
'order' => 'DESC',
'showposts' => '3');
$recent_posts = get_posts($args);
foreach($recent_posts as $recent){
echo '<li><a href="' . get_permalink($recent->ID) . '" title="Look '.$recent->post_title.'" >' . $recent->post_title.'</a>' . $recent->post_excerpt . ' </li> ';
}
?>
確保您post_excerpt
不是空
如果您要添加的post_excerpt
然後使用wp_update_post
$my_post = array();
$my_post['ID'] = 37;// it is important
$my_post['post_excerpt'] = 'This is the updated post excerpt.';
wp_update_post($my_post);
根據你的要求評論我顯示你的演示用所以這裏複製在post_excerpt
的post_title
更新post
你去
<?php
$args = array('post_type'=>'post',
'orderby'=>'post_date',
'post_status'=>'publish',
'order' => 'DESC',
'showposts' => '3');
$recent_posts = get_posts($args);
foreach($recent_posts as $recent){ // this foreach to add the excerpt
$my_post = array();
$my_post['ID'] = $recent->ID;// it is important
$my_post['post_excerpt'] = $recent->post_content;
wp_update_post($my_post);
}
foreach($recent_posts as $recent){ // this foreach to show the excerpt
echo '<li><a href="' . get_permalink($recent->ID) . '" title="Look '.$recent->post_title.'" >' . $recent->post_title.'</a>' . $recent->post_excerpt . ' </li> ';
}
?>
wp_update_post
另見wp_insert_post
這仍然不會輸出任何摘錄。你能向我解釋如何使摘錄不是「空的」?我認爲節錄內容截短。 – Francesca
var_dump($ recent_posts);看看裏面有什麼 –
@Francesca查看我的更新回答 –