Hi,
I have this repeater with 3 fields:
start date, end date and price and i have like 3-4 rows like this:
12/12/2016 24/12/2016 $400
24/12/2016 31/12/2016 $500
etc
i need to get the price for the selected dates, is it posible with an acf function or should i do it in other way?
This is the repeater code:
array (
'key' => 'field_572b858626762',
'label' => 'dates',
'name' => 'dates_repeater',
'type' => 'repeater',
'collapsed' => 'field_572b859f26763',
'layout' => 'table',
'button_label' => 'add date',
'sub_fields' => array (
array (
'key' => 'field_572b859f26763',
'label' => 'Start',
'name' => 'date_start',
'type' => 'date_picker',
'display_format' => 'd/m/Y',
'return_format' => 'Y-m-d',
'first_day' => 1,
),
array (
'key' => 'field_572b86927bb0e',
'label' => 'End',
'name' => 'date_end',
'type' => 'date_picker',
'display_format' => 'd/m/Y',
'return_format' => 'Y-m-d',
'first_day' => 1,
),
array (
'key' => 'field_57ab9b20dd22a',
'label' => 'Price',
'name' => 'price_by_dates',
'type' => 'text',
'instructions' => '',
'append' => '€',
),
),
),
The only way you can get a specific row based on at value is to loop over the repeater until you find what you’re looking for and then show it.
if (have_rows('dates_repeater')) {
while (have_rows('dates_repeater')) {
the_row();
$now = date('Ymd'); // this is the format stored by ACF
// the above is also the format you need to use to compare dates
// the second parameter of <code>false</code> tells ACF not to format
// the value so that we can compare them
if (get_sub_field('date_start', false) >= $now &&
get_sub_field('date_end', false) <= $now) {
the_sub_field('price_by_dates');
}
}
}
The topic ‘Get specific values from repeater’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.