Date Queries

The date query feature in WordPress only works with the actual date columns in the WP database (post_date and post_modified). If you’re trying to use a date stored as metadata, you’ll want to use a Meta Query. Here are some examples of meta queries using dates:


There are 8 parameters for managing date queries:

  • date — Serves as a shortcut to setting the ‘year’, ‘month’, and ‘day’ arguments for a given date query struct on the second-level. It accepts either a strictly-formatted ‘YYYY-MM-DD’ date string or a relative-formatted date string, such as ‘Sunday, September 7’. The relative-formatted string is intended as a fallback for the easier-to-sanitize ‘YYYY-MM-DD’ formatted string and could prove fickle when supplied with too little information.
  • date_column — The first of two top-level arguments, this serves as the “global” column to query for all date queries in the date query arrays on the second-level. This defaults to ‘post_date’.
  • date_compare — The second of two top-level arguments, this serves as the “global” comparison operator for all date queries in the date query arrays on the second-level. This defaults to ‘=’.
  • date_query_before — Sets the ‘before’ argument for a date query on the second level. It accepts either a strictly-formatted date, ‘YYYY-MM-DD’, or as a fallback, a relative-formatted date string (using the same logic as the date attribute).
  • date_query_after — Sets the ‘after’ argument for a date query on the second level. Like the date_query_before attribute, It accepts either a a strictly-formatted date, ‘YYYY-MM-DD’, or as a fallback, a relative-formatted date string (using the same logic as the date attribute.
  • date_query_column — Sets the column to query by for the second-level date query. If not set, falls back to the value of date_column.
  • date_query_compare — Sets the comparison operator for the second-level date query. If not set, falls back to the value of date_compare.
  • time — Serves as a shortcut to populating the ‘hour’, ‘minute’, and ‘second’ arguments in the second-level date query. It accepts only a strictly-formatted string in the format of ‘HH:MM:SS’ or ‘HH:MM’. This does NOT have a string falback.

Here are some sample shortcodes: Query for posts published on a specific date:

[[display-posts date="2014-09-07"]]

Query for posts published after January 1, 2013:

[[display-posts date_query_after="2013-01-01"]]

Query for posts published BEFORE today:

[[display-posts date_query_before="today"]]

Query for posts modified yesterday:

[[display-posts date="yesterday" date_query_column="post_modified"]]

For more information, see the Date Query pull request.

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.