Support

Account

Home Forums Add-ons Repeater Field Festival events sorted by date/time by using posts and repeater field Reply To: Festival events sorted by date/time by using posts and repeater field

  • Hi @imaginedd

    Thank you for showing the way 🙂

    I have tried that example code and now i have all events from each band on specific date. The problem is that i’m not sure how to sort it by time sub field.

    Here is the code:

    <?php
    $date = "20160620";
    // args
    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> 'band',
    	'meta_query'	=> array(
    		'relation'		=> 'OR',
    		array(
    			'key'		=> 'events_%_date',
    			'compare'	=> '==',
    			'value'		=> $date,
    		)
    	)
    );
    
    $the_query = new WP_Query( $args );
    ?>
    
    <?php if( $the_query->have_posts() ): ?>
    	<div class="events">
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<?php
    		if(have_rows('events')):
    		   while(have_rows('events')): the_row();
    			  if(get_sub_field('date') == $date):
    				 the_sub_field('time');
    				 echo ' - ';
    				 the_title();
    				 echo '<br>';
    			  endif;
    		   endwhile;
    		endif;
    		?>
    	<?php endwhile; ?>
    	</div>
    <?php endif; ?>
    
    <?php wp_reset_query();	 ?>

    By this code i’m getting such events lst:

    1500 – Band1 (1st show)
    1800 – Band 1 (2nd show)
    1400 – Band 2 (2nd show)
    1200 – Band 2 (1st show)

    I’m not sure how to use krsort() with repeater. Can you help me with this?

    Many thanks!