How to display total views of all posts of one category?

Question

Is there any way to display total views of all posts of one category? How to show that number on archive page? I have used this code to count views of each post:

function getPostViews($postID){
    $count_key ='post_views_count';
    $count = get_post_meta($postID, $count_key,true);
    if($count=='' || $count < 0){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key,'0');
        return"0 Views";
    }
    return $count.' Views';}function setPostViews($postID){
    $count_key ='post_views_count';
    $count = get_post_meta($postID, $count_key,true);
    if($count=='' || $count < 0){
        $count =0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key,'0');
    }else{
        $count = $count + 1;
        update_post_meta($postID, $count_key, $count);
    }
  }

But how to count total views for one category and display it? Please help me!

0
, , user3106691 3 years 2020-05-31T04:10:19-05:00 0 Answers 97 views 0

Leave an answer

Browse
Browse