Support

Account

Home Forums General Issues Order Query by Time Picker not working

Unread

Order Query by Time Picker not working

  • Hi,

    I’ve got a query of posts which is returning the correct posts for a particular day but when I try and order the query using an ACF Time Picker field it doesn’t sort them correctly.

    Im using code:

    	// Set Post Type
    	$query->set( 'post_type', [ 'sessions' ] );
    	
    	// Set Posts per page
    	$query->set( 'posts_per_page', -1 );
    	
    	// Get current meta Query
    	$meta_query = $query->get( 'meta_query' );
    
    	// If there is no meta query when this filter runs, it should be initialized as an empty array.
    	if ( ! $meta_query ) {
    		$meta_query = [];
    	}
    
    	// Set Query Dates
    	$qry_offset_monday = $_GET['offset'];
    	if (!$qry_offset_monday) $qry_offset_monday = 0;
    
    	$str_monday = "monday this week +" . $qry_offset_monday . " week";
    	
    	$date_monday = date('Ymd', strtotime($str_monday));
    	
    	// Append our meta query
    	$meta_query[] = [
    		'key' => 'session_date',
    		'value' => $date_monday,
    		'type' => 'DATE',
    	];
    
    	$query->set( 'meta_query', $meta_query );
    	
    	// Set Ordering
    	$query->set( 'order', [ 'ASC' ] );
    	$query->set( 'orderby', [ 'meta_value_time' ] );
    	$query->set( 'meta_key', [ 'session_time' ] );
    	$query->set( 'meta_type', [ 'TIME' ] );
    

    I’ve tried using orderby set to meta_value, meta_value_num and meta_value_time and nothing seems to work.

    I’d appreciate any help that anyone could give.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.