Support

Account

Home Forums Add-ons Repeater Field Dynamically add sub fields to a repeater

Solved

Dynamically add sub fields to a repeater

  • Hi everyone,

    I’m trying to dynamically add sub_fields to a repeater field using php.
    What I need is adding one or more sub_fields based on certain criteria.

    I’m using the prepare_field filter to add sub_fields as following

    function my_acf_prepare_field( $field ) {
    	
        $field['sub_fields'][] = array(
    	'key' => 'custom_key',
    	'label' => 'Custom Name',
    	'name' => 'custom_name',
    	'type' => 'text',
    	'instructions' => '',
    	'required' => 0,
    	'conditional_logic' => 0,
    	'wrapper' => array(
    		'width' => '',
    		'class' => '',
    		'id' => '',
    	),
    	'default_value' => '',
    	'placeholder' => '',
    	'prepend' => '',
    	'append' => '',
    	'maxlength' => '',
        );
    
        return $field;
        
    }
    add_filter('acf/prepare_field', 'my_acf_prepare_field');

    this way ACF will show any sub fields correctly in the post edit screen.
    The problem is that is not able to save any input value related to this dynamic sub fields.

    Someone could point me in the right direction on how to achieve this?
    Any suggestion would more apreciated.
    Thanks in advance

  • @hube2
    Thanks John, it solves the problem!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Dynamically add sub fields to a repeater’ is closed to new replies.