看来你得和current user.
因为这是一个通知系统,你必须post Ids 按当前用户并全局检查。
否则,你必须检查每一个帖子。您将无法从网站的任何位置访问这些值。
这是获取最新(注释,注释用户id)的代码。。。全局:)
// Grab all posts\' (array)ids by current user
function current_author_post_ids() {
global $current_user;
$args = array(
\'author\' => $current_user->ID,
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1
); // get all posts
$author_posts = get_posts($args);
// check if only one id return
if (count($author_posts) > 1) {
$allIds = array();
foreach ($author_posts as $c_post) :
$allIds[] = $c_post->ID;
endforeach;
return $allIds;
} else {
return $author_posts[0]->ID;
}
}
function get_last_comment_and_author_id() {
$args = array(
\'number\' => \'1\',
\'post__in\' => current_author_post_ids(),
\'orderby\' => \'post_date\',
// order by Time Stamp Here
// \'oderby\' => \'meta_type\' TIME
\'order\' => \'DSC\',
\'posts_per_page\' => 1
); // get only one comment
// Get the latest comment
$comments = get_comments($args);
foreach ($comments as $comment) :
echo \'Last author ID =\' . $comment->user_id . \'<br>\';
echo \'Last author =\' . $comment->comment_author . \'<br>\';
echo \'Last Comment =\' . $comment->comment_content;
endforeach;
}
要获取值,可以运行此函数
<?php echo get_last_comment_and_author_id(); ?>