0

I'm currently working on a plugin that contains a shortcode which allows users to filter a custom post type by date. They could choose "Date From", "Date To", and "Date From with Date To".

When using the inclusive flag, it ignores the inclusive flag and does not select the date that is entered in the shortcode. For instance if I had selected datefrom=1/10/2013 and dateto=05/16/2014 it selects only the posts between 1/10/2013 and 5/15/2014. If I want to select 5/16/2014 I have to make dateto=5/17/2014.

What is the proper usage?

Here is what I currently have:

  //both datefrom and dateto
    if (($datefrom != "") && ($dateto != "")){
        $args['date_query'] = array(
            array('after' => $datefrom,
            'before' => $dateto),
            'inclusive' => true);
    }

Thanks for your time!

0

Your arrays seem malformed :

    $args['date_query'] = array(
        array(
            'after'     => $datefrom,
            'before'    => $dateto,
            'inclusive' => true
        )
    );

Also check here and be sure you are passing dates with proper string format !

  • Using the follow based on your answer, is still failing to grab the expected results. I think that it only goes till the stroke of midnight on May 16, so it's not grabbing the rest of the day. – plumwd Jun 4 '14 at 14:01

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.