Support

Account

Home Forums Front-end Issues Order Query by Date Picker

Solved

Order Query by Date Picker

  • Hello,

    I tried to find a solution for this in the forums but to no avail.

    I have a custom post type ‘events’ each post has two ACF fields ‘event_start_date’ and ‘event_end_date’.

    I want my query to only show events that have an end date in the future but I want the events to be ordered by the start date. The following code will show events that have a ‘event_end_date’ in the future but are also ordered by the ‘event_end_date’ field.

    Any help to how to introduce the second meta query for order by ‘event_start_date’ would be appreciated.

    $meta_query = array(
    			array(
    				'key' => 'event_end_date',
    				'value' => date('Ymd'),
    				'type' => 'DATE',
    				'compare' => '>=',
    			)
    		);			
                $args = array(
                    'post_type' => 'events',
    				'orderby' => 'meta_value_num',
    				'order'	=> 'ASC',
                    'posts_per_page' => '115',
    				'meta_query' => $meta_query
                );
    

    Thank you.

  • I got it sorted and wanted to post the solution

    $meta_query = array(
    			array(
    				
    				'key' => 'event_end_date',
    				'value' => date('Ymd'),
    				'type' => 'DATE',
    				'compare' => '>='
    				)
    			
    		);			
                $args = array(
                    'post_type' => 'events',
    				'orderby' => 'meta_value_num',
    				'meta_key' => 'event_start_date',
    				'order'	=> 'ASC',
                    'posts_per_page' => '115',
    				'meta_query' => $meta_query
                );
  • Hi @paudiefearon

    Great that you managed to find the solution yourself. There’s quite a bit of posts like these in the forum and there is also some examples of this in the documentation. Please feel free to mark your own answer as the solution so this topic is closed properly.

    Thank you.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Order Query by Date Picker’ is closed to new replies.