Support

Account

Home Forums General Issues Addling an alert message when the query is empty

Helping

Addling an alert message when the query is empty

  • Hello, I have a code here that updates the sponsor_username when I entered a username, I want to add an alert message when the query is empty or the username does not exist, I tried to use acf/validate_value but still no luck.

    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();
    		}
    }
  • The only way is with an acf/validate_value filter.

    What have you tried?

    You would do the same query and if it returns no results then you would return an error message.

    You would probably be better off using a select field with Stylized UI which uses Select2 and provides a search and then dynamically generating the select values from available users.

    Or better yet, a user field.

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

You must be logged in to reply to this topic.