WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Easily retrieve Wordpress blog statistics 

Easily retrieve WordPress blog statistics 

01.02.2023 by William Lam // Leave a Comment

Happy New Year! 🥳

I wanted to kick off the new year with something that I had shared at the end of 2022, which was a break down on the number of blog posts that I have published over the years.

Since @rhjensen was asking about number of blog posts compared to previous years ....

With some quick PowerShell Automation, here's all my blog post breakdown from 2010-2022 along with the sum, minimum, maximum and average. Sounds like 2015 was an interesting year 😁 pic.twitter.com/WIt2KZ34Qa

— William Lam (@lamw.bsky.social | @*protected email*) (@lamw) December 16, 2022

A number of folks had reached out asking how they could do the same for their own blogs and so I wanted to share the solution that I had used.

The solution that I am using is only applicable for blogs powered by WordPress and is not relavent to other blogging platforms. There are a ton of different ways to retrieve blog statistics from WordPress, including various 3rd party solutions as well as the built-in WordPress stats, but I opted for this solution as I found the default stats system has negatively impacted the performance of my blog due to the volume of traffic and thus I have disabled the default stats collection.

While searching online for an alternative solution that did not require a plugin installation, I came to learn that every WordPress deployment includes a public API endpoint as part of its normal functionality. I browsed the WordPress API Reference and saw that the /posts API would allow me to quickly summarize all of my blog articles.

Note: If you wish to disable your public WordPress API, you can follow this tutorial (using the code snippet option as that is the most recommended over installing a new plugin).

One thing to note is that the Posts API unfortunately does not allow for a high level GET operation, it pulls down the entire blog post and its content, which I would have preferred a filter option that gave only the basic information (e.g. title, date published, etc) and for more details, you could then get the content if needed. In either case, this did not affect the use of the API and everything was pretty snappy and with a bit of testing, I came up with the following PowerShell script:

$yearStart = "2007"
$wordpressUrl = "https://yellow-bricks.com"

### DO NOT EDIT BEYOND HERE ####

$blogs = @{}
foreach ($year in $yearStart..(Get-Date).Year) {
    $tmp1 = (Invoke-WebRequest -Uri "${wordpressUrl}/wp-json/wp/v2/posts?per_page=100&after=${year}-01-01T00:00:00.000&before=${year}-06-31T00:00:00.000").Content | ConvertFrom-Json
    $tmp2 = (Invoke-WebRequest -Uri "${wordpressUrl}/wp-json/wp/v2/posts?per_page=100&after=${year}-06-31T00:00:01.000&before=${year}-12-31T00:00:00.000").Content | ConvertFrom-Json
    $result = $tmp1.count + $tmp2.count
    $blogs[[int]$year] = $result
}

Write-Host -ForegroundColor Cyan "`nHere is the blog post breakdown for ${wordpressUrl} across $(${blogs}.count) years ..."
$blogs | Sort-Object -Property Name

Write-Host -ForegroundColor Cyan "`nTotal   Blog Count: $(($blogs.values | Measure-Object -Sum).Sum)"
Write-Host -ForegroundColor Cyan "Least   Blog Count: $(($blogs.values | Measure-Object -Minimum).Minimum)"
Write-Host -ForegroundColor Cyan "Most    Blog Count: $(($blogs.values | Measure-Object -Maximum).Maximum)"
Write-Host -ForegroundColor Cyan "Average Blog Count: $([int]($blogs.values | Measure-Object -Average).Average)`n"

There are only two variables that you need to fill in, the first is the year in which your blog had started and the second is the URL of the WordPress blog. In the example above, I am checking my buddy Duncan Epping's blog, the famous yellow-bricks. Due to the maximum results of 100, I have broken the query into first half of the year and second half of the year to aggregate the total number of blog posts and then tallying up along with minimum, maximum and average blog post counts.

Here is the output for running the script above:


As you can see, Duncan is already off strong for 2023 with his first blog post already 😀

Note: If you wish to disable the

I also had some fun checking out some of my other favorite VMware Bloggers, which I had also shared on Twitter:

Having some fun w/Automation & few of my favorite blogs from @DuncanYB @FrankDenneman @CormacJHogan @alanrenouf … just wow, the amount of knowledge that has been shared from these combined over past decade+ is insane!👏

One person here has been responsible for hiring all of us! pic.twitter.com/himIBxFZfy

— William Lam (@lamw.bsky.social | @*protected email*) (@lamw) December 16, 2022

More from my site

  • Exploring GenAI with a private ChatGPT solution using my own blog posts
  • 1,000th post - The story behind virtuallyGhetto
  • virtuallyGhetto gets a bit less ghetto ...
  • Deployment models for vSphere Content Library
  • How to install Windows 11 Arm with a vTPM using ESXi-Arm v1.11 

Categories // Automation Tags // blogging, wordpress

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025

 

Loading Comments...