I have a nested repeater field (repeater inside another repeater) with a ‘select’ field inside that, and I basically just want to output the label for each item in the select field.
I have read the documentation, which shows the following:
$field = get_field_object('field_name'); $value = get_field('field_name'); $label = $field['choices'][ $value ];
However I can’t get this to work within a nested repeater. Is there a way around this?
For info, I am using ACF v3.5
Any help much appreciated
The get_field_object function only works with parent fields. To find a sub field object, please use the get_sub_field_object function.
This function is documented below and was added in v4:
Perhaps for now, you could use a work around like so:
<?php $field = get_field_object('repeater_field_name'); $sub_fields = $field['sub_fields']; // debug variable to find the sub field key ($key) echo '<pre>'; print_r($sub_fields); echo '</pre>'; die; $sub_field = $sub_fields[ $key ]; ?>
Thank you for replying. I should point out that my PHP knowledge isn’t that great(!). I did however get the following output:
Array ( [field_51e6a66b8509b] => Array ( [label] => Client name [name] => client_name [type] => text [instructions] => [column_width] => [default_value] => [formatting] => html [order_no] => 0 [key] => field_51e6a66b8509b ) [field_51e6a6788509c] => Array ( [label] => Client logo [name] => client_logo [type] => image [instructions] => [column_width] => [save_format] => url [preview_size] => thumbnail [order_no] => 1 [key] => field_51e6a6788509c ) [field_51e6a6878509d] => Array ( [label] => Images [name] => images [type] => repeater [instructions] => [column_width] => [sub_fields] => Array ( [field_51e6a69f8509e] => Array ( [label] => Large image [name] => large_image [type] => image [instructions] => [column_width] => [save_format] => url [preview_size] => thumbnail [order_no] => 0 [key] => field_51e6a69f8509e ) [field_51e9070105abe] => Array ( [choices] => Array ( [kitchen] => Kitchen [lounge] => Lounge [hallway] => Hallway [meeting_room] => Meeting Room [bathroom] => Bathroom [reception] => Reception [bedroom] => bedroom ) [label] => Location [name] => location [type] => select [instructions] => [column_width] => [default_value] => [allow_null] => 0 [multiple] => 0 [order_no] => 1 [key] => field_51e9070105abe ) ) [row_min] => 0 [row_limit] => [layout] => table [button_label] => Add Row [order_no] => 2 [key] => field_51e6a6878509d ) )
What I basically want is to output the ‘choices’ array from the above. I’ve taken a look into multidimensional arrays and understand them (ish!), but not when they’re this deep. Do you know how I can output the ‘choices’?
The topic ‘Show select field label within nested 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!
Lifetime license customers: we are still firmly committed to honoring lifetime licenses. In all future emails, we will reaffirm this commitment so there is no confusion. -BT— Advanced Custom Fields (@wp_acf) November 29, 2021
© 2021 Advanced Custom Fields.