Skip to main content
update to not refer to the "suggestion above" now that my answer is the top one.
Source Link
jerclarke
  • 3.1k
  • 2
  • 28
  • 35

Copied from StackOverflow:

WP_Query offers a date_query parameter, allowing you to set a range with before and after.

https://developer.wordpress.org/reference/classes/wp_query/#date-parameters

$args = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2015',
            'before'    => 'December 31st, 2015',
            'inclusive' => true,
        ),
    ),
);
$query = new WP_Query( $args );

The above suggestion of usingSee the linked documentation for more details.

Note that the other answer, which uses a postmeta query, is really out of date, no one should do that now that WP_Query supports these date queries.

Copied from StackOverflow:

WP_Query offers a date_query parameter, allowing you to set a range with before and after.

https://developer.wordpress.org/reference/classes/wp_query/#date-parameters

$args = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2015',
            'before'    => 'December 31st, 2015',
            'inclusive' => true,
        ),
    ),
);
$query = new WP_Query( $args );

The above suggestion of using a postmeta query is really out of date, no one should do that now that WP_Query supports these date queries.

Copied from StackOverflow:

WP_Query offers a date_query parameter, allowing you to set a range with before and after.

https://developer.wordpress.org/reference/classes/wp_query/#date-parameters

$args = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2015',
            'before'    => 'December 31st, 2015',
            'inclusive' => true,
        ),
    ),
);
$query = new WP_Query( $args );

See the linked documentation for more details.

Note that the other answer, which uses a postmeta query, is really out of date, no one should do that now that WP_Query supports these date queries.

Copied from StackOverflow:

WP_Query offers a date_query parameter, allowing you to set a range with before and after.

https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parametershttps://developer.wordpress.org/reference/classes/wp_query/#date-parameters

$args = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2015',
            'before'    => 'December 31st, 2015',
            'inclusive' => true,
        ),
    ),
);
$query = new WP_Query( $args );

The above suggestion of using a postmeta query is really out of date, no one should do that now that WP_Query supports these date queries.

Copied from StackOverflow:

WP_Query offers a date_query parameter, allowing you to set a range with before and after.

https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters

$args = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2015',
            'before'    => 'December 31st, 2015',
            'inclusive' => true,
        ),
    ),
);
$query = new WP_Query( $args );

The above suggestion of using a postmeta query is really out of date, no one should do that now that WP_Query supports these date queries.

Copied from StackOverflow:

WP_Query offers a date_query parameter, allowing you to set a range with before and after.

https://developer.wordpress.org/reference/classes/wp_query/#date-parameters

$args = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2015',
            'before'    => 'December 31st, 2015',
            'inclusive' => true,
        ),
    ),
);
$query = new WP_Query( $args );

The above suggestion of using a postmeta query is really out of date, no one should do that now that WP_Query supports these date queries.

Source Link
jerclarke
  • 3.1k
  • 2
  • 28
  • 35

Copied from StackOverflow:

WP_Query offers a date_query parameter, allowing you to set a range with before and after.

https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters

$args = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2015',
            'before'    => 'December 31st, 2015',
            'inclusive' => true,
        ),
    ),
);
$query = new WP_Query( $args );

The above suggestion of using a postmeta query is really out of date, no one should do that now that WP_Query supports these date queries.