Using stats_get_csv to return a list of popular posts by views with thumbnails

The API returns the following columns when you query the postviews table:

  • date
  • post_id
  • post_title
  • post_permalink
  • views

For my blog the post_id column was either empty or 0 (for the homepage). So unless you have good values there, you will have to work from the post_permalink value and determine whether it is a page or a post (via a query on the database or a regex on the URL?), and then query your database for the post thumbnail, because the WordPress.com stats API does not collect info on that.

Leave a Comment