GD Press Tools tracks number of views for posts and pages, and also tracks users activities for posts and pages. Data is gathered on a daily basis. Here are two functions you can use to get totals of views per post and also views data for each user and post.
Getting post views
First function is:
presstools_get_post_views($post_id = 0)
If $post_id is set to zero, function will attempt to get post ID from current post. If this fails, error will be returned. If it’s OK, object with views information for that post will be returned. This object contains these properties:
- post_id: post ID
- users_views: number views from users
- visitors_views: number of views from visitors
- total_views: total number of views
Getting users post views
First function is:
presstools_get_user_views($id = 0, $all_posts = false, $post_id = 0)
First parameter is ID for user. If this is set to zero, plugin will attempt to get ID for current user. Second paramter set to true will return array with views for all posts for user. If parameter remains false, plugin will get views for post specified with third parameter. If this one is zero, function will attempt to get post ID from current post. If any problem occures with paramters, function will return error.
Here are some examples:
presstools_get_user_views(11, true);
This will return views for all posts for user with ID 11.
presstools_get_user_views(31, false);
This will return views for current post for user with ID 31.
presstools_get_user_views(31, false, 4);
This will return views for post with ID 4 for user with ID 31.






Comment Link
Thanks Milan for this function. I tried to use presstools_get_post_views function in single.php but no luck. I did something wrong. Could you please send me sample code?
Comment Link
As I said, there is tutorial, you don’t need anything else.
Comment Link
Wonderful. Works very well on my blog. Check out http://arpitshah.com
Thanks again.
Comment Link
I just can’t work out the code to show total views… Could you please post example code to do this?
Comment Link
All the code you need is in the post. I don’t understand what more do you need, it’s very simple.
Comment Link
When i put that code in, the site goes white (blank).
What would be the code to see total visitors.
Because just copy/paste of that code doesn’t work for me. Am I missing something? Just putting that top line into PHP tags doesn’t do anything but blank the site page.
Comment Link
Do you used GD Press Tools plugin? It’s needed for this to work, WP doesn’t track anything, GD Press Tools does that.
Comment Link
Yes of course. I’m using GD press tools…
It’s a rather simple question, if you was going to put this into a page what would be the code?
I get that you posted the code up top, but simply putting that into some php tags doesn’t do anything.
I want the total number of current post views.
phptag code to use endphptag
Comment Link
Functions above work, I guarantee you. And if you read what the text says: function WILL RETURN, and that means that function result will be number of views. You need to use some of the print functions to display that, like `echo`.
Comment Link
Try this:
total_views;
echo $view1;
?>
I’m using it here: http://arpitshah.com/sitemap/
Comment Link
Oops, php part removed from my comment.
Visit this: http://arpitshah.com/gd-press-tools-show-tracking/
Just created above port.
Comment Link
Is there any way to sort posts by most views? A lot of plugins have this functionality but it doesn’t seem like GD does….