Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5878
    radukn
    Participant

    Greetings! I know you provide a shortcode, but if I want to add post views counter in a template what is the PHP function? Thank you very much!

    #5882
    Bartosz
    Keymaster

    Hi,

    There is a couple of functions:

    pvc_get_post_views($post_id) – to get post views for a post or array of posts
    pvc_get_most_viewed_posts($args) – get most viewed posts, a wrapper for get_posts() function, forcing orderby parameter to “post_views”
    pvc_post_views($post_id, $echo) – display post views for a given post
    pvc_most_viewed_posts($args, $echo) – display a list of most viewed posts

    #7170
    Coptic Treasures
    Participant

    Hi,
    elaborating on the abover reply, is there a function to display the total number of views for all the posts combined?
    the closest one i found in the reply is :
    pvc_get_post_views($post_id) – to get post views for a post or array of posts
    pvc_post_views($post_id, $echo) – display post views for a given post

    however, i don’t know how to specify the “array of posts” mentioned. so i can specify a big range to cover all the posts.

    any advice?
    Cheers

    #7171
    Coptic Treasures
    Participant

    Hi,
    elaborating on the abover reply, is there a function to display the total number of views for all the posts combined?
    the closest one i found in the reply is :
    pvc_get_post_views($post_id) – to get post views for a post or array of posts
    pvc_post_views($post_id, $echo) – display post views for a given post

    however, i don’t know how to specify the “array of posts” mentioned. so i can specify a big range to cover all the posts.

    any advice?
    Cheers

    #7172
    Bartosz
    Keymaster

    There’s no smart way to do that with a function yet. We’re working to extend the plugin API with multiple parameters but for now just go with the sql query:

    global $wpdb;
    
    $total_views = (int) $wpdb->get_var( "
    	SELECT SUM(count) AS views
    	FROM " . $wpdb->prefix . "post_views
    	WHERE type = 4"
    ); 
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.