0

I have a custom meta call post_views_count that collects the views of all posts...

I want to create a query that pulls in all posts by a certain author, gathers the custom meta for post views and then add them all together.

End result - Total view count for all authors posts...

1 Answer 1

0

Maybe not the most elegant solution

 

$authorPost = get_posts(array('author' => 1));foreach ($catPost as $post) {
    setup_postdata($post);
    $ids[] = get_the_ID();
}
$idList = implode(",", $ids); //turn the array into a comma delimited list

$meta_key = 'post_view';
$allview = $wpdb->get_var($wpdb->prepare("
                                  SELECT sum(meta_value) 
                                  FROM $wpdb->postmeta 
                                  WHERE meta_key = %s 
                                  AND post_id in (" . $idList . ")", $meta_key));
echo '

user 1 All posts View Count'.$allview .'

';
1
  • Cheers that worked perfectly :)
    – Phil Nind
    Commented Apr 8, 2015 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.