Support

Account

Home Forums General Issues How to order by date field Reply To: How to order by date field

  • Ok, tried this:

    <?php 
     
    $today = date('MM d, yy');
     
    $args = array (
        'post_type' => 'post',
        'meta_query' => array(
            array(
                'meta_key'  => 'event_date',
                'compare'   => '>=',
                'value'     => $today,
            ),
             array(
                'meta_key' => 'event_date',
                'orderby' => 'meta_value_num',
                'order' => 'ASC',
                'cat' => '2'
            )
        ),
    );
    
        $the_query = new WP_Query( $args );
        
        
        if ( $the_query->have_posts() ) {
            while ( $the_query->have_posts() ) {
                
                $the_query->the_post(); ?>

    But it does not return the correct result. It shows all the events.