Support

Account

Home Forums General Issues Dynamic select box field values

Solved

Dynamic select box field values

  • Hi

    I’d like to know if I can populate a select box dynamically. I want to have an “author” field, with dynamically defined values

  • You could make use of the load_field filter:
    http://www.advancedcustomfields.com/resources/filters/acfload_field/

    This should get you going!

    
    function dynamic_author_dropdown( $field ){
    	
    	$authors = get_users(array(
    		'role' => 'author'
    	));
    	
    	if(!empty($authors)){
    		foreach($authors as $author){
    			$field['choices'][$author->ID] = $author->display_name;
    		}
    	}
     
        return $field;
    }
     
    // acf/load_field/key={$field_key} - filter for a specific field based on it's key name , CHANGE THIS TO YOUR FIELDS KEY!
    add_filter('acf/load_field/key=field_508a263b40457', 'dynamic_author_dropdown');
    
  • thanks! already figured it out and it works perfectly!

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

You must be logged in to reply to this topic.