Support

Account

Home Forums Add-ons Repeater Field Problem with generated "Repeater" field

Unread

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_”!!!

Viewing 1 post (of 1 total)

The topic ‘Problem with generated "Repeater" field’ is closed to new replies.