Home › Forums › Add-ons › Repeater Field › Problem with generated "Repeater" field
I have a “Repeater” field which is generated like this:
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_custom_object',
'title' => 'Custom Object',
'fields' => array (
array (
'key' => 'custom_images',
'label' => 'Images',
'name' => 'image_urls',
'type' => 'repeater',
'sub_fields' => array (
array (
'key' => 'custom_image',
'label' => 'Image',
'name' => 'image_url',
'type' => 'text',
'column_width' => '',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
),
'row_min' => '',
'row_limit' => '',
'layout' => 'row',
'button_label' => 'Add Row',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'my_custom_post_type',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'default',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}
The field is NOT generated by Admin GUI, it gets generated in my functions.php together with the custom post type it belongs to.
No I have the problem, that I could not add repeating values by a hook. It seems like in my hooked function the fields generated by code and not by GUI are not known/fillable?!
Hooked function:
function post_saved($post_id)
{
$images = array('test1.jpg', 'test2.jpg', 'test3.jpg');
$values = array();
foreach ($images as $n => $image) {
$values[]['image_url'] = $image;
}
update_field('field_53562b25c883a', $values, $post_id);
}
add_action('pmxi_saved_post', 'post_saved', 10, 1);
UPDATE:
Ok, I’ve found the reason why the field (generated in functions.php) is not recognized in other hooks. It seems like the fields have to start with “field_”!!!
The topic ‘Problem with generated "Repeater" field’ 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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.