当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Couting total views on all posts of an author, but the first

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: