我正在使用WordPress 3.4.2。《codex》没有提到任何关于此函数被弃用的内容:http://codex.wordpress.org/Function_Reference/get_most_recent_post_of_user
为什么我收到致命错误:调用未定义的函数Get_Most_Recent_Post_of_User()?
1 个回复
最合适的回答,由SO网友:Chris_O 整理而成
get\\u most\\u recent\\u post\\u of\\u user()用于多站点安装,以从每个博客获取用户的最新帖子。
这里有一个可比较的函数,您可以使用它返回定义用户最近发布的帖子的帖子对象。
function wpse_get_user_recent( $user ) {
global $wpdb;
$recent = $wpdb->get_row( $wpdb->prepare("SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = \'post\' AND post_status = \'publish\' ORDER BY post_date_gmt DESC LIMIT 1", (int)$user ), ARRAY_A);
if( ! isset( $recent[\'ID\'] ) )
return new WP_Error( \'No post found for selected user\' );
return get_post( $recent[\'ID\'], \'ARRAY_A\' );
}
用法:$post = wpse_get_user_recent( 36 );
setup_post_data( $post );
the_title();
the_content();
wp_reset_postdata();
结束