Support

Account

Home Forums Backend Issues (wp-admin) How can I register fields via php when a post is saved Reply To: How can I register fields via php when a post is saved

  • When you are registering the fields in when you call acf_add_local_field_group() you need to get the value that was previously saved.

    
    if( function_exists('acf_add_local_field_group') ):
    
    $label = 'Default Label';
    // code to do something like get a new field label will go here
    // what you need to do depends on where you're saving the
    // value that you want to use
    
    acf_add_local_field_group(array(
    	'key' => 'group_1',
    	'title' => 'My Group',
    	'fields' => array (
    		array (
    			'key' => 'field_1',
    			'label' => $label,
    			'name' => 'sub_title',
    			'type' => 'text',
    		)
    	),
    	'location' => array (
    		array (
    			array (
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'test_type_1',
    			),
    		),
    	),
    ));
    
    endif;