Home › Forums › General Issues › Get value from specific row in nested repeater
I am trying to figure out how to get a value from a specific row in a nested repeater.
What I am trying to do is creating a natural language form (http://tympanus.net/Tutorials/NaturalLanguageForm/) that can change the position of the options in the dropdown based on how which one is used most. I also want the possibility to easily change questions via backend administration that then generates the form. So I have chosen to use nested repeaters.
So whenever a user makes a choice and presses search I use som ajax magic to send in which row they have selected from.
I have solved it so I can update that specific row with whatever value I want. But I can’t for the world figure out how I can get the value from a specific row and then do an $count++ to increment the value.
I have wrote some comments in my code below. But the problem is the to get the value from a specific row.
function update_select_rows($array_selected_fields) {
// This array looks something like this ["1", "2", "2", "4", "3", "2"]. Where each selection is a pair. So the first two numbers in this array tells me that the user has selected form the 1:st question the 2:nd value.
$array_selected_fields_count = count($array_selected_fields) / 2;
while ($array_selected_fields_count >= 1) {
$row_outer_pos = $array_selected_fields_count * 2 - 2;
$row_inner_pos = $array_selected_fields_count * 2 - 1;
$row_outer_id = $array_selected_fields[$row_outer_pos];
$row_inner_id = $array_selected_fields[$row_inner_pos];
//This is the problem. I cant for the world figure out how to get the value.
$count_uses = get_sub_field( array('field_57472d5d5b2b8', $row_outer_id, 'field_57472d735b2b9', $row_inner_id, 'field_57481c6a50018'), 'options' );
$count_uses++;
//This works flawless and I can update the specific row inside the nested repeater.
update_sub_field( array('field_57472d5d5b2b8', $row_outer_id, 'field_57472d735b2b9', $row_inner_id, 'field_57481c6a50018'), $count, 'options' );
$array_selected_fields_count--;
}
}
Just figured out the solution to this myself so I share it here
$nfl_question_repeater = get_field('nl_form_questions', 'options' );
//Just change the number here to specify the first repeater row
$row_outer = $nfl_question_repeater[0];
$row_question = $row_outer['question'];
//Just change the number here to specify the nested repeater row
$row_inner = $row_question[1];
$row_inner_value = $row_inner['uses'];
You must be logged in to reply to this topic.
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 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.