Home > other >  Show User Role when username is being type in wordpress
Show User Role when username is being type in wordpress

Time:10-24

I have here 2 textfields for Username and Role, I want to show the role automatically when I typed the username on the textbox, can anyone please help me? I'm new on wordpress, any help would be so much appreciated. Thankyou enter image description here

CodePudding user response:

I made this work using acf/savepost

add_action('acf/save_post', 'my_acfe_save', 10, 2);
    
    function my_acfe_save(){
        
        $list_id   = get_the_ID();
        $username_info = get_field('username' ,$list_id);
            
        $the_query = new WP_User_Query( array( 'search' => esc_attr($username_info), 
         ) );
        $show_all = $the_query ->get_results();
        
            if(!empty($show_all) ) { 
    
                 foreach ($show_all as $user){  
    
                    $author_info = get_userdata($user->ID);
                    $sponsor_username =  $author_info->user_registration_sponsor_username;
    
                    update_field('sponsor_username', $sponsor_username);
               } 
                wp_reset_query();
            }
    }
  • Related