Support

Account

Home Forums General Issues Sorting using ACF Date field Reply To: Sorting using ACF Date field

  • John, thank you for the tips, but I think my knowledge is too little. Is it more or less like this?

    $now = date('Y-m-d H:i:s');
    
    	$meta_query = array(
    
    		'meta_query'   => array(
    
    			'relation'      => 'OR',
    
    				array(
    					'event_start' => array(
    						'key'       => 'start_date',
    						'compare'   => '<',
    						'value'     => $now,
    						'type'      => 'DATETIME'
    					),
    					'event_end'   => array(
    						'key'       => 'end_date',
    						'compare'   => '>',
    						'value'     => $now,
    						'type'      => 'DATETIME'
    					),
    				),
    
    				array(
    					'event_upcoming' => array(
    						'key'       => 'start_date',
    						'compare'   => '>=',
    						'value'     => $now,
    						'type'      => 'DATETIME'
    					)
    				),
    
    				array(
    					'event_past' => array(
    						'key'       => 'end_date',
    						'compare'   => '<',
    						'value'     => $now,
    						'type'      => 'DATETIME'
    					),
    				),
    			),
    		);
    
    		$query->set('meta_query', $meta_query);
    
    		$query->set(
    			'orderby',
    			array(
    				'event_start' => 'DESC',
    				'event_end' => 'DESC',
    				'event_upcoming' => 'DESC',
    				'event_past' => 'ASC',
    			)
    		);
    
    		$query->set('order', 'ASC');

    I have no ideas anymore and I am broken 🙁