WP_Date_Query Generator

Overview

Use this tool to create custom code for WordPress Date Query with WP_Date_Query class.

Usage

  • Fill in the user-friendly form.
  • Click the “Update Code” button.
  • Copy the code to your project.
  • Or save it as a snippet and share with the community.

Examples

If you are still learning how to use this tool, check out the following examples:

The variable used in the code.
The MySQL keyword used to join the clauses of the query.
Operator used for comparing the value.
Textual date/time description.
Select from your saved Date Query snippets.
Comparing column other than the one in the top-level column.
Textual date/time description.
Include results from dates specified, or not.
Operator used for comparing the value.
Textual date/time description.
Select from your saved Date Query snippets.
Comparing column other than the one in the top-level column.
Textual date/time description.
Include results from dates specified, or not.
Operator used for comparing the value.
Textual date/time description.
Select from your saved Date Query snippets.
Comparing column other than the one in the top-level column.
Textual date/time description.
Include results from dates specified, or not.
Operator used for comparing the value.
Textual date/time description.
Select from your saved Date Query snippets.
Comparing column other than the one in the top-level column.
Textual date/time description.
Include results from dates specified, or not.
Operator used for comparing the value.
Textual date/time description.
Select from your saved Date Query snippets.
Comparing column other than the one in the top-level column.
Textual date/time description.
Include results from dates specified, or not.
  Save Snippet
$date_query = array(
	'relation' => 'OR',
	array(
		'relation' => 'OR',
		array(
			'before' => array(
				'month' => 2,
			),
			'after' => array(
				'month' => 1,
			),
			'inclusive' => true,
		),
		array(
			'after'         => '2 months ago',
		),
	),
	array(
		'relation' => 'AND',
		array(
			'after'         => '1 year ago',
		),
		array(
			'dayofweek'     => 1,
			'compare'       => '!=',
		),
	),
);