I want to output the associated label with a specific select value but doing a print_r on the field shows that [label] and [value] is empty.
The select field lives as one of many fields under a repeater field. The choices are URL : Name, so for example,
http://www.google.com : Google
http://www.yahoo.com : Yahoo
My code is as such:
$repeater = get_field('repeater_name');
if($repeater) {
foreach($repeater as $r) {
$select = $r['select_field'];
$object = get_field_object($select);
print_r($object);
}
}
Doing a print_r outputs the following:
Array
(
[key] => field_http://www.google.com
[label] =>
[name] => http://www.google.com
[type] => text
[order_no] => 1
[instructions] =>
[required] => 0
[id] => acf-field-http://www.google.com
[class] => text
[conditional_logic] => Array
(
[status] => 0
[allorany] => all
[rules] => 0
)
[default_value] =>
[formatting] => html
[maxlength] =>
[placeholder] =>
[prepend] =>
[append] =>
[value] =>
)
I want to be able to output the label (Google) as well as the value (http://www.google.com)…
I hope this makes sense.
Hi @turtlemimi
There are a few issues with your code. Because the field is infact a sub field, you need to use the function get_sub_field_object:
http://www.advancedcustomfields.com/resources/functions/get_sub_field_object/
To use that function you need to change your foreach loop to a while( has_sub_field ) loop.
The other issue with your code is that you are sending through the sub field value as the parameter to the get_sub_field function. You need to pass through the field_name, as per the docs
Thanks
E