We’ve created various helper functions that make it easy to work with WordPress.com Stats data. You can find these functions in the following helper file: vip-helper-stats-wpcom.php. This file is auto-loaded for you.
Note: Please use these functions with care as they can be fairly resource-intensive and can cause issues if abused under high traffic scenarios.
Getting Most Popular Posts #
The following helper function returns popular posts for a specified number of days:
wpcom_vip_top_posts_array. It returns data in the raw format returned by the Stats API. If you don’t care much about the actual view count, you can easily use the returned post_id to fetch the full post objects.
Getting Other Data #
wpcom_vip_get_stats_array function, you can retrieve the following data:
- views (daily views)
- postviews (top posts)
- referrers (top referrers)
- searchterms (top referring search terms)
- clicks (top outbound clicks)
- authorviews (top authors)
Stats API #
WordPress.com Stats has a nice API to fetch all sorts of cool data too! For access to this data outside of your WordPress.com site/theme, please read our documentation here.