Support

Account

Home Forums Backend Issues (wp-admin) Generate fields for each select option

Solving

Generate fields for each select option

  • Hello,

    I populate select field on an option page with this :

    function acf_load_clients_field_choices( $field ) {
    
    	// reset choices
    	$field['choices'] = array();
    	$users = get_users( array( 'fields' => array( 'display_name' ) ) );
    	$users = array_column($users, 'display_name');
    	// remove any unwanted white space
    	$users = array_map('trim', $users);
    
    	if( is_array($users) ) {
    		foreach( $users as $choice ) {
    			$field['choices'][ $choice ] = $choice;
    		}
    	}
    	
    	return $field;
    
    }
    
    add_filter('acf/load_field/name=clients', 'acf_load_clients_field_choices');
    

    Now, I would like to display a unique field for each of these option on my option page. For example, if I select option A with the select field, I would like an A text field to appear.

    I can’t use the “Conditional logic”, because my select fiel is dynamically populated.

  • No, what you would need to do is to generate the conditional field and all of the related fields dynamically using PHP https://www.advancedcustomfields.com/resources/register-fields-via-php/.

    For example you can create fields in ACF and export to PHP to see what you need to do.

    But it’s just not possible using the ACF admin.

  • @hube2 makes total sense to me.

    @24prod I have been using ACF-Builder and it works incredibly well, you might want to give it a shot:

    https://github.com/StoutLogic/acf-builder/

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

You must be logged in to reply to this topic.