试试这个
<?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
复制post_title
来更新post_excerpt
<?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