Support

Account

Home Forums Add-ons Repeater Field Sort/filter repeater by date Reply To: Sort/filter repeater by date

  • You could setup your repeater field with a date and text field (see attached image). Then under the selected page / post type, just fill the repeater rows with dates (using date picker) and corresponding dates.

    Then on the page (I’m using a custom post type “Movies” in this example – and a template “single-movie.php”) just put this PHP code to get “quote of the day”:

    <?php
    
    // GET TODAY'S DATE IN THE SAME FORMAT AS YOUR DATE SUB-FIELD
    $today = date('Ymd'); // 20140503
    
    // CHECK IF REPEATER HAS ROWS
    if( have_rows('quote_of_the_day') ):
    	
     	// LOOP TROUGH REPEATER ROWS
        while ( have_rows('quote_of_the_day') ) : the_row();
            
            // IF THE REPEATER SUB-FIELD MATCHES TODAY'S DATE, SHOW QUOTE SUB FIELD
            if (get_sub_field('date') == $today) {
            	 the_sub_field('quote');
            }
            
        endwhile;
        
    endif;
    
    ?>