0

I want to order the array by a date field called date_start but how do I include a meta key for this if I already have one?

$currentshowid = get_the_ID();
$today = date('Y-m-d');
$args = array(
    'meta_key' => 'show_id',
    'meta_value' => $currentshowid,
    'orderby' => 'meta_value_num',
    'order' => ASC,
    'meta_query' =>array(
        'relation' => 'AND',
        array(
            'key' => 'date_end',
            'value' => $today,
            'compare' => '>=',
        ),
    ),
);
0

You need to use the type parameter for custom field. Try this once

<?php 
$currentshowid = get_the_ID();
$today = date('Y-m-d');
$args = array(
              'meta_key' => 'show_id',
              'meta_value'  => $currentshowid,
              'orderby' => 'meta_value_num',
              'order' => ASC,
              'meta_query' =>array(
                                'relation' => 'AND',
                                array(
                                'key'       => 'date_end',
                                'value'   => $today,
                                'compare'   => '>=', 
                                'type'    => 'date'                               
                                ),
                            ),
          ); 

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.