Support

Account

Home Forums General Issues Ordering In An Array In A Specific Category Reply To: Ordering In An Array In A Specific Category

  • I received a reply through email and wanted to post the code in case there are others with the same issue. Here’s the code that I’m now using:

    
    $date2018 = '2018';
    $date_range_2018 = array( $date2018 . '-01-01', $date2018 . '-12-31' );
    
    $posts2018_args = array(
                'post_type' => 'events',
                'posts_per_page' => -1,
                'meta_key' => 'event_date',
                'orderby' => 'meta_value_num',
                'order' => 'ASC',
                    'meta_query' => array(
                        'relation' => 'AND',
                        
                        array(
                            'key' => 'event_category',
                            'value' => 'Indoor Track and Field',
                            'compare' => '=',
                        ),
    
                        array(
                            'key' => 'event_date',
                            'value' => $date_range_2018,
                            'compare' => 'BETWEEN',
                            'type' => 'DATE',
                        ),
    
                    ),
                );
    
            $posts2018 = get_posts( $posts2018_args );
    

    Thanks