Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Advanced Custom Fields help with repeater field sub select fields WordPress



I am using [[LINK href=""]]advanced custom fields[[/LINK]].

I have a [[LINK href=""]]repeater field[[/LINK]]. Inside this repeater field, I have a [[LINK href=""]]select field[[/LINK]].

<?php if(get_field('promotions_codes' )): ?>

<div class="btn-group">

<?php while(has_sub_field('promotions_codes' )): ?>


$field = get_field_object('promotions_codes' );
$value = get_sub_field('select_promotion' );
$label = $field['choices' ][ $value ];


<a class="btn" href="<?php echo $value; ?>" title="<?php echo $label; ?>" target="_blank"><?php echo $label; ?></a>

<?php endwhile; ?>


<?php endif; ?>

I have simply created a repeater field called <strong>promotions_codes</strong>

Then the sub select field in my repeater is called <strong>select_promotion</strong>

My select field options are... : Low Rate Finance : Free Accessories : Extended Warranty

The code above seems to work fine, but the only thing that I can't seem to echo is the <strong>$label</strong>.

So my question is, can anyone help me see what I'm doing, and how can I echo the <strong>$label</strong> ?

So I asked Elliot at ACF, to see if he could help me understand where I am going wrong.

[[LINK href=""]]See discussion here.[[/LINK]]

He kindly replied, but I am struggling to understand what he means. This is what he said...

The problem is with your $label variable. You need to get the choices from the sub field, not the parent field.

What you can do is use $field to look at the 'sub_fields' array. Your sub field will be in there.

Then you can find the 'choices' from your sub_field.

Just use print_r($field) to understand how the data is setup

So I did what he said and printed $field, and this what I got...

Array (
[key] => field_5076967aedf64
[label] => Promotions Codes
[name] => promotions_codes
[type]=> repeater
[order_no] => 0
[instructions] =>
[required] => 0
[conditional_logic] => Array (
[status] => 0
[rules] => Array (
[0] => Array (
[field] => null [operator] => ==
[allorany] => all
[sub_fields] => Array (

[field_4] => Array (
[choices] => Array (
[] => Low Rate Finance
[] => Free Accessories
[] => Extended Warranty
[label] => Promotion
[name] => select_promotion
[type] => select
[instructions] =>
[column_width] =>
[default_value] =>
[allow_null] => 1
[multiple] => 0
[order_no] => 0
[key] => field_4

[row_min] => 0
[row_limit] =>
[layout] => table
[button_label] => Add Promotion
[value] => Array (
[0] => Array (
[select_promotion] =>

Though I'm not sure how to get the sub field object from this?

I tried this...

$field = get_field_object('promotions_codes');
$subField = $field['sub_fields'];
$value = get_sub_field('select_promotion');
$label = $subField['choices'][ $value ];

But I am still having no such luck echo'ing the $label of my select sub field.

Can anyone help please.


Answers (1)


paul de wouters answers:

shouldn't it be $field['sub_fields']['field_4']['choices']

Josh Cranwell comments:

Ahhh thanks.

I tried this did not work...

$field = get_field_object('promotions_codes');
$value = get_sub_field('select_promotion');
$label = $field['sub_fields']['field_4']['choices'][ $value ];

But I tried this and it did work...

$field = get_field_object('promotions_codes');
$subField = $field['sub_fields']['field_4'];
$value = get_sub_field('select_promotion');
$label = $subField['choices'][ $value ];

So thank you!