Social Media Logotype Background

How to retreive shares count from WordPress posts

This script will get number of shares of a post url from usual social networks and return the information as JSON.

Social networks


  • Facebook’s likes and shares
  • Twitter
  • LinkedIn’s shares
  • Google plus’ shares


(You are free to put it anywhere you want if you know how to access it by url, of course.)

  • Drop the file getShares.php in your wordpress main directory, next to wp-config.php file.
  • Call the file by url, per example:


By default, the script return the last seven days posts, sorted by date of publication (by wordpress) and displayed in a table.
You can override this with parameters:


The script will return posts from the last day, sorted by shares count and in JSON format.

The link


  • Add a parameter to get result for only one specific url.

Published by

Constantin Guay

Currently Data Project Manager and Scrum Evangelist at NetMediaEurope, european leader in IT B2B news site (more than 12 million unique visitors per month). Passionate by user experience and data science. Scrum evangelist