Hello,
Is there a way to return an array using get_post_meta and repeater field?
I have ACF fields: repeater -> select field (color)
return format: value and label (array).
Below code works perfectly:
if( have_rows('repeater_value') ):
while( have_rows('repeater_value') ) : the_row();
// Load sub field value.
$color = get_sub_field( 'color' );
$value = $color['value'];
$label = $color['label'];
endwhile;
else :
endif;
I would like to achieve the same thing with get_post_meta.
Below code not working:
$repeater_value = get_post_meta( get_the_ID(), 'repeater_value', true);
if ( $repeater_value ) {
for ($i=0; $i<$repeater_value; $i++) {
$meta_key = 'repeater_value_' . $i . '_color';
$color = get_post_meta( get_the_ID(), $meta_key, true );
// not working
$value = $color['value'];
$label= $color['label'];
}
}
How to do it?
Thanks for help.
Best regards,
Tomasz P.
what type of field is the sub field “color”?
John Huebner,
type of field is select (advancedcustomfields.com/resources/select/). Return Format: “Both (Array)”.
The value stored in a select field does not include the label. The values stored in the DB is a single text value if the select field only allows a single value. An array of text values are stored in multiple values can be selected.
The values are just the values.
There is no way to retrieve the values without using ACF.
See get_field_object() to get the labels.