Grouping posts by month using post meta

In this snippet, I will show you how to do go grouping posts by month using post meta. Why? Sometimes you have a date field and within your custom fields especially for travel agency plugins and you kinda want to count how many bookings are made in each month.

This is very useful if you want to create search filter by date.

Here’s how I did it.

Notice that I’ve used an SQL script for this one? here’s some explanation about the parameters.

prefix – The table prefix will vary depending for the site owner. It could be ‘wp’ or ‘xp’ so in order to be safe use this parameter.

get_results – Is the type is an SQL function by WordPress to that returns the entire query result as an array. Whatever script you use that will be the result.

Leave a Reply

Your email address will not be published. Required fields are marked *

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