以下代码将检查是否有记录摘录:
if ( has_excerpt( $post->ID ) ) {
// This post has excerpt
} else {
// This post has no excerpt
}
以下代码将返回1条包含摘录的记录:
function get_random_post_by_excerpt($post_type){
global $wpdb;
$id_post = $wpdb->get_var($wpdb->prepare("SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_type = \'%s\' AND $wpdb->posts.post_status = \'publish\' AND $wpdb->posts.post_excerpt != \'\' ORDER BY RAND();", $post_type));
return $id_post = (!empty($id_post))?$id_post:false;
}
调用函数:
$post_id = get_random_post_by_excerpt(\'post\');