Home Forums Add-ons Repeater Field Upcoming events list ordered by date.


Upcoming events list ordered by date.

  • [I read all topics related but I’m still confused about what to do]

    I have a list of upcoming events, each event can have up to 5 upcoming dates (using the repeater field). I need to sort those events by date, when the first date has passed the events should reorder based on the next date and so…only one date should be shown per event at a time (that would be really awesome but I understand if it’s not possible).

    What I have:

    function display_events(){
    	$args = array(
    		'post_type' => 'events',
    		'posts_per_page' => '12',
    		'orderby' => 'menu_order');
    	$events = '';	
    	$loop = new WP_Query( $args );
    	if( $loop->have_posts() ){
    	$events .= '<div class="events-list"><div class="one-third first"><ul>';
    	while ( $loop->have_posts() ) {
    		if (have_rows('dates')) {
    			$dates = array();
    			while(have_rows('dates')) {
    			$date = get_sub_field('date', false, false);
    			if ($date) {
    			$dates[] = date_i18n('j \d\e\ F', strtotime($date));
    			} // end while have rows
    	$events .= '<li><a class="title" href="' . get_permalink() . '" rel="bookmark" title="'. get_the_title() . '">' . get_the_title() . '</a><span class="date">' . implode(' | ', $dates) . '</span><span class="info"><a href="' . get_permalink() . '" rel="bookmark" title="'. get_the_title() . '">More info</a></span></li>';
    	$events .= '</ul></div>';
    	return $events;

    This code displays the following list:

    date1, date2, date3
    More info

    dat1, date2
    More info

    date1, date2, date3, date4
    More info

  • Hi @maira

    If you need to order the events based on the date in a repeater, then you need to query the repeater instead of the events. This page should give you more idea about it:

    You also need to select the field values based on the current time and remove the duplicated post ID. This page should give you more idea about it:

    If you need more help to create the SQL query, please visit WordPress and MySQL community.

    I hope this helps 🙂

  • Thanks James, seems too advanced for me at the moment. Would it be easier to achieve if I use single Date Time Picker fields, instead of a Repeater field?

  • Hi @maira

    If it’s too advanced, I suggest you hire a developer to help you out with it, and I’d recommend looking for one on,, or

    If you use a single Date Time Picker, that would make things much simpler. Please check this page to learn more about it:

    Hope this helps 🙂

  • Awesome, I’ll check that option. Hiring another dev is out of the client budget, but she’s quite flexible about the options for this events list.


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

The topic ‘Upcoming events list ordered by date.’ is closed to new replies.