Show post views of all the authors in the last 7 days

What I’m trying to achieve here is to show post views of all the authors in the website in last 7 days. Total post views of all the authors present in the website during the last 7 days..

Here is what I tried:

$author_id = get_users (array('role' => 'Author'));

$author_posts = get_posts (array('author' => $author_id, 'posts_per_page'=>20, 
'date_query' => array(
 array('after' => '7 days ago')) ) ); $counter = 0; for each ( $author_posts as $post ){

$views = getauthorspostview($post->ID);

$counter += floor($views);
}

echo "{$counter} ";

I’m really not sure whether – get_users(array (‘role’ => ‘Author’)); can get the id’s of all the authors in a website but it seems only showing the views count of displayed or current users.. They all works but it shows only the total views of current users in last 7 days.

Volunteered help will be highly appreciated.

Read more here: Show post views of all the authors in the last 7 days

Leave a Reply

Your email address will not be published. Required fields are marked *