A practical use for the new date queries in WP 3.7

Recent Contributors Widget

A couple of weeks ago, Alex Mills (better known as Viper007Bond) wrote a post, noting that a patch he had written for WordPress core had been committed, and will be included in 3.7.

The patch makes specific and complex date queries in WP_Query much easier. This historically has been very difficult, with the date queries only allowing for posts/comments to be pulled for a specific date.

The new date queries allows you to, for example, query posts since a specific date/time, or everything posted on weekdays in the past month. See Alex’s post on complex date queries to read a little more about what’s possible.

This made me think of an application a few years ago that I couldn’t solve. Someone asked me to build them a widget which would show a list of everyone who had contributed to their site in the past month, as a way of recognising them. I soon found that it was more difficult than I thought, and abandoned it.

But after hearing about the new possibilities with date queries, I knew my main problem had been solved.

I built a widget that takes the list of users on your site, runs each one through a WP_Query, using the date query to see if they have written anything in the past 30 days (or however long you want), and if they have, it prints them out to a list.

It’s fairly simple, but it’s a solution to a problem that stumped me a couple of years ago, and now it’s possible.

Expect to see the Recent Contributors Widget in the repository soon.

2 thoughts on “A practical use for the new date queries in WP 3.7”

  1. Nick Hilden says:

    I’m liking the sound of your Recent Contributors Widget – it’s absolutely perfect for my multi-author website and will be installing it as soon as it becomes available.

    1. It’s available now :) http://wordpress.org/plugins/recent-contributors-widget/ Bear in mind that it requires WP 3.7, so it might not yet work on your site if you’re still running 3.6.x.

Leave a Reply