Support

Account

Home Forums ACF PRO Dynamic select box field values from another database

Solved

Dynamic select box field values from another database

  • I’d like to know if I can populate a select box dynamically from another database.

    Thanks.
    Regards,
    Microtag

  • function dynamic_dropdown( $field ){
    
    $wpdbtest_otherdb = new wpdb('password', 'user', 'db', 'host');
    $wpdbtest_otherdb->show_errors();
    $user_logins = $wpdbtest_otherdb->get_results("SELECT * FROM wp_users");
    
    	if(!empty($user_logins)){
    		foreach($user_logins as $user_login){
    			$field['choices'][$user_login->ID] = $user_login->display_name;
    		}
    	}
    
        return $field;
    }
     
    add_filter('acf/load_field/key=field_xxxxxxx', 'dynamic_dropdown');
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.