问题描述:

I'm using a code to count the total number of views of the logged user's posts, but for some reason, it's not adding to the total the user's first post views. The funny part is that I've tested this in other users and it seems to behave like this only in my admin account.

This is the code:

<?php

$author_posts = get_posts( array('author' => $current_user->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}";

?>

Any help is very much appreciated.

相关阅读:
Top