1

I'm trying to get wordpress post by filtering date and time, for example get post 01/02/2014 to 07/02/2014. thanks for the help me.

  • So you want to retrieve all posts published between 2 dates? – Tom J Nowell Feb 7 '14 at 11:46
1

Try to use new WP_Query for this.
Add a new query and pass below argument.

$args = array(
    'date_query' => array(
        array(
            'after'     => '2014-02-01',
            'before'    => '2014-02-07',
            'inclusive' => true,
        ),
     ),
);

$my_query = new WP_Query( $args );
1

There are lot of date related parameters you can specify in a custom query. You have to use WP_query to fire a new query to get the results. In this scenario your custom query should contain parameters 'date_query' along with other parameters. I have tried it and It worked for me. Just change your dates.

$query_agrs = array(
        'date_query' => array(
            array(
                'before' => 'January 2nd, 2014',
                'after' => 'December 1st 2013'
                ),
            'inclusive' => true
            ),
        'posts_per_page' => -1
        );
$my_query = wp_query($query_agrs);
while($my_query->have_posts()): $my_query->the_post();
the_title();
endwhile;

There is an alternative way to define 'before' and 'after' too.

You can also write the before parameter like this:

'before' => array('year' => 2014, 'month' => 1, 'day' => 2)

similarly with 'after' parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.