7

Advanced Date Queries in WordPress – 3.7

On October 24, 2013, WordPress Version 3.7, named for Count Basie, was released. It has some cool new features and one of those is that, developers can now query for posts within a date range, or that are older than or newer than a specific point in time using date_query .

For example, to get posts dated December 12, 2012, we can write the query like this:

Or using date_query , we can write:

To get posts for today, we can write:

Or using date_query , we can write:

To get posts for this week, we can write:

Or using date_query , we can write:

To get posts between 9am to 5pm on specific weekdays using date_query, we can write:

To get posts from January 1st to February 28th using date_query, we can write:

Another amaging date_query to return posts made over a year ago but modified in the past month (this is really cool), we can write:

It also works for comments, for example, to get all comments from post ID 10 that are within the past week, we can write:

This is really cool and this patch made by Alex Mills (AKA) Viper007Bond on internet (also wrote many WordPress Plugins including SyntaxHighlighter Evolved, that I’m currently using on my blog), so credit goes to him. Read more on Codex about date_query and also learn more about new features of WordPress Version-3.7.

Latest Blog

0

New Union Type in PHP – 8

A new RFC has been finished voting and accepted for PHP – 8. That is “Union Types”, which is an extension of PHP’s type system. […]