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

  • Try using acf/load_field filter instead https://www.advancedcustomfields.com/resources/acf-load_field/

  • @hube2
    Thanks John, it solves the problem!

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.