get_most_recent_post_of_user [ WordPress Function ]
get_most_recent_post_of_user ( $user_id )
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: wp_get_recent_posts, get_blogs_of_user, get_comment_statuses, get_parent_post_rel_link, get_author_posts_url
Get a user's most recent post.
Walks through each of a user's blogs to find the post with the most recent post_date_gmt.
Source
<?php
function get_most_recent_post_of_user( $user_id ) {
global $wpdb;
$user_blogs = get_blogs_of_user( (int) $user_id );
$most_recent_post = array();
// Walk through each blog and get the most recent post
// published by $user_id
foreach ( (array) $user_blogs as $blog ) {
$prefix = $wpdb->get_blog_prefix( $blog->userblog_id );
$recent_post = $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", $user_id ), ARRAY_A);
// Make sure we found a post
if ( isset($recent_post['ID']) ) {
$post_gmt_ts = strtotime($recent_post['post_date_gmt']);
// If this is the first post checked or if this post is
// newer than the current recent post, make it the new
// most recent post.
if ( !isset($most_recent_post['post_gmt_ts']) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) {
$most_recent_post = array(
'blog_id' => $blog->userblog_id,
'post_id' => $recent_post['ID'],
'post_date_gmt' => $recent_post['post_date_gmt'],
'post_gmt_ts' => $post_gmt_ts
);
}
}
}
return $most_recent_post;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/get most recent post of user « WordPress Codex
Description. Get the most recent post of a user. Walks through each of a user's blogs to find the post with the most recent post_date_gmt.
codex.wordpress.org - #19891 (get_most_recent_post_of_user() should use ...
Given the loop over multiple sites and the direct DB query against each post table , this function should probably be deprecated and killed. That said, it currently ...
core.trac.wordpress.org - get_most_recent_post_of_user | A HitchHackers guide through ...
Feb 12, 2011 ... function get_most_recent_post_of_user( $user_id ) { global $wpdb; $user_blogs = get_blogs_of_user( (int) $user_id ); $most_recent_post ...
hitchhackerguide.com - ms-functions.php
May 7, 2010 ... get_dashboard_blog(). get_dirsize(). get_most_active_blogs(). get_most_recent_post_of_user(). get_sitestats(), Multi-site WordPress API ...
www.tig12.net