Support

Account

Home Forums General Issues How to sort by ACF field Reply To: How to sort by ACF field

  • Hi,
    you can do it like this:

    $currentDate = date('Ymd');	
    $args = array(
        'numberposts' => -1,
        'meta_key' => 'date',
        'orderby' => 'meta_value_num',
        'order' => 'ASC',
    	'meta_query' => array( 
             array( 
    	        'key'		=> 'date',
    	        'compare'	=> '>=',
    	        'value'		=> $currentDate,
                ),
    	 )
    	);

    this would return all the posts where the “date” field is equal to the current date or later. (you would need to change the “date” on my code to your “event_date” field name and add other arguments you may want to have like “cat”=> ‘2’ the save format of your date field should be set to yymmdd