Support

Account

Home Forums Front-end Issues Order by ACF Date, then by Custom Field

Solved

Order by ACF Date, then by Custom Field

  • First of all just want to say love the plugin and the community support here, i’ve learnt so much from these forums.

    I haven’t been able to work this one out though.

    Basically I’m trying to display a list of upcoming events by their location and then ordered by the date – this I have achieved with the following code.

    <?php $args = array(
    				'post_type' => 'page',
    				'posts_per_page' => -1,
    				'orderby' => 'meta_value_num',
    				'meta_key' => 'race_date',
    				'order' => 'ASC',
    				'meta_query' => array(
    				'relation' => 'AND',
    					array(
    						'key' => 'race_date',
    						'compare' => '<='
    					)    ,
    					array(
    						'key'	  	=> 'race_state',
    						'value'	  	=> 'vic',
    						'compare' 	=> '=',
    					),   
    					) 
    				);
        $my_query = new WP_Query($args); if ($my_query->have_posts()) : ?>

    This works fine for now but what I want to do is then order these events by another custom field called race_class.

    I have set this field up as a select field with these choices.

    g1 : Group 1
    g2 : Group 2
    g3 : Group 3
    listed : Listed
    other : Other

    However I’m not sure how to progress with this. Ideally would love to have events displayed like…

    October 19 – Event Title – Group 1
    October 19 – Event Title – Group 2
    October 19 – Event Title – Group 3
    October 19 – Event Title – Other
    October 20 – Event Title – Group 1
    October 20 – Event Title – Group 2
    October 20 – Event Title – Group 3
    October 20 – Event Title – Other

    If someone could help me with this I would be very grateful 🙂

  • Beauty, thanks a lot!

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

The topic ‘Order by ACF Date, then by Custom Field’ is closed to new replies.