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;
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.