Title: PHP function to retrieve single post visits
Last modified: August 30, 2016

---

# PHP function to retrieve single post visits

 *  Resolved [Stefano](https://wordpress.org/support/users/ste_95/)
 * (@ste_95)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/php-function-to-retrieve-single-post-visits/)
 * Hi there,
    is there any function that, given a post id/WP post object, returns
   the number of visits for it? Or may I can write my own PHP function to do that?
 * Thanks!
 * [https://wordpress.org/plugins/wp-slimstat/](https://wordpress.org/plugins/wp-slimstat/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Contributor [Jason Crouse](https://wordpress.org/support/users/coolmann/)
 * (@coolmann)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/php-function-to-retrieve-single-post-visits/#post-6264121)
 * Hi,
 * we are (still) working on the documentation. What you can do is to include wp-
   slimstat-db.php and then do:
 *     ```
       $filters = 'content_id equals ' . $post->ID;
       wp_slimstat_db::init( $filters );
       $count_post_views = wp_slimstat_db::count_records();
       ```
   
 * where $post->ID is the global object and can be replaced with other WP functions
   depending on where you are (inside the Loop, etc).
 * Please note that by default, count_records returns the number of pageviews during
   the current month. If you want ALL the pageviews from the beginning, you’ll use:
 * wp_slimstat_db::count_records( ‘id’, ”, false);
 * Hope this helps,
    Camu
 *  Thread Starter [Stefano](https://wordpress.org/support/users/ste_95/)
 * (@ste_95)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/php-function-to-retrieve-single-post-visits/#post-6264123)
 * Thanks man, that was **really** helpful! This has just allowed me to allow integration
   of your plugin with mine 🙂
 *  Plugin Contributor [Jason Crouse](https://wordpress.org/support/users/coolmann/)
 * (@coolmann)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/php-function-to-retrieve-single-post-visits/#post-6264129)
 * I tested your plugin and integration, well done sir! 🙂 We’re working on the 
   documentation (sigh!) to allow other developers to do what you did.
 *  Thread Starter [Stefano](https://wordpress.org/support/users/ste_95/)
 * (@ste_95)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/php-function-to-retrieve-single-post-visits/#post-6264135)
 * Thanks! I do well understand what you’re going through: the documentation for
   my own plugin is poor and it would just be such a giant effort to write all that
   would be needed!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘PHP function to retrieve single post visits’ is closed to new replies.

 * ![](https://ps.w.org/wp-slimstat/assets/icon.svg?rev=2832242)
 * [SlimStat Analytics](https://wordpress.org/plugins/wp-slimstat/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-slimstat/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-slimstat/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-slimstat/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-slimstat/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-slimstat/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Stefano](https://wordpress.org/support/users/ste_95/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/php-function-to-retrieve-single-post-visits/#post-6264135)
 * Status: resolved