这个$current_user
对象检索当前登录的用户。您需要的是您正在查看其页面的作者的ID。尝试以下操作:
global $wp_query;
$author_id = $wp_query->queried_object_id;
$author_posts = get_posts( array(\'author\' => $author_id) );
$counter = 0; // needed to collect the total sum of views
foreach ( $author_posts as $post ) {
$views = absint( get_post_meta( $post->ID, \'post_views_count\', true ) );
$counter += $views;
}
echo "{$counter}";
回显视图,查看是否有:
foreach ( $author_posts as $post ) {
$views = absint( get_post_meta( $post->ID, \'post_views_count\', true ) );
var_dump($views);
$counter += $views;
}