Support

Account

Home Forums General Issues Sorting posts by two custom fields Reply To: Sorting posts by two custom fields

  • I changed it like this. It seems to work. If I changed correctly.

    $posts = get_posts( array(
    					'numberposts' 	=> -1,
    					'post_type'  	=> 'order-item',
                        'meta_query'    =>  array(
                            'relation'  =>  'AND',
                            'order_status'  =>  array(
                                'key'       => 'order_status',
                                'value'     =>  array(1,2,3,4,5),
                            ),
                            'order_date_end'    => array(
                                'key'       => 'order_date_end',
                                'compare'   =>  'EXISTS',
                            )
                        ),
                        'orderby'   =>  array(
                            'order_status' =>   "ASC",
                            'order_date_end' =>   "DESC",
                        ),
    				) );