0

I am trying to query a custom post type that has a meta value (DATE) that are equal or greater than today. My issue is that some posts have the date stored in the "Ymd" format and others have "Y-m-dTg:i a".

This is what I currently have. It currently isn't ordering properly.

'posts_per_page'   => -1,
    'orderby'          => 'meta_value_num',
    'order'            => 'ASC',
    'post_type'        => 'funeral',
    'post_status'      => 'publish',
    'meta_query' => array(
        array(
            'relation' => 'OR',
            array(
                'key' => 'service_date',
                'value' => date('Ymd'),
                'compare' => '>=',
                'type' => 'DATE'
            ),
            array(
                'key' => 'service_date',
                'value' => date('Y-m-dTg:i a'),
                'compare' => '>=',
                'type' => 'DATE'
            )
        )
)
  • What format is service_date in the database? – Howdy_McGee Feb 27 at 21:59
  • 1
    Have you considered consolidating on a single format? A custom WP CLI command could do that, as could a WP Cron job, or a quick AJAX polling – Tom J Nowell Feb 27 at 22:39

Your Answer

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

Browse other questions tagged or ask your own question.