Support

Account

Home Forums General Issues A point on Date fields in WP_Query Reply To: A point on Date fields in WP_Query

  • Hi,

    I received an email that tell that the user Feyfey answered my thread, however for a weird reason, I can’t see the post here.

    For my first question, I presume it was ok to said that ACF finally asigned an empty string (and not a null value) in the meta key. Maybe it happens when entering and removing a date manually in the field, then save the post. However I haven’t been able to make work the “NOT EXISTS” comparasion yet.

    For my second one, here’s finally a group of arguments which worked for me :

       $date_limit = date('Y-m-d', strtotime("-3 days"));
        $args = array(
            'post_type'      => 'vehicle',
            'meta_key'       => 'date_sell',
            'meta_query'     => array(
                'relation' => 'OR',
                array(
                    'key' => 'date_sell',
                    'compare' => '>=',
                    'value' => $date_limit,
                    'type' => 'DATE'
                ),
                array(
                    'key' => 'date_sell',
                    'compare' => '=',
                    'value' => ''
                )
            )
        );

    So with a Date type and ‘Y-m-d’ format.

    Hope it’ll help.

    Nox