Title: WordPress Users Search
Last modified: October 31, 2022

---

# WordPress Users Search

 *  [alitheabdullah](https://wordpress.org/support/users/alitheabdullah/)
 * (@alitheabdullah)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/wordpress-users-search/)
 * Hi, I created an Ajax search where users can search custom post types and the
   results will automatically come up, here is the code. I need to know what changes
   I can make to this code so it searches WordPress Users by their names and some
   custom post types that I have created.
    Thanks
 *     ```
       add_action('wp_ajax_nopriv_data_fetch','data_fetch');
       function data_fetch(){
   
           $the_query = new WP_Query( array( 'posts_per_page' => 10, 's' => esc_attr( $_POST['keyword'] ), 'post_type' => array ('capabilities' , 'industry-users') ) );
           if( $the_query->have_posts() ) :
               while( $the_query->have_posts() ): $the_query->the_post(); ?>
   
                   <a href="<?php echo esc_url( post_permalink() ); ?>"><?php the_title();?></a>
   
               <?php endwhile;
       		wp_reset_postdata();  
       	else: 
       		echo '<h3>No Results Found</h3>';
           endif;
   
           die();
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [Hugh Lashbrooke](https://wordpress.org/support/users/hlashbrooke/)
 * (@hlashbrooke)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/wordpress-users-search/#post-16151194)
 * Because WordPress users are not stored as posts, you cannot search both posts
   and users in a single query. To search users, you will need to use [WP_User_Query](https://developer.wordpress.org/reference/classes/wp_user_query/)
   or [get_users](https://developer.wordpress.org/reference/functions/get_users/).
 * You could do two separate queries and then use a tool like PHP’s [array_merge](https://www.php.net/manual/en/function.array-merge.php)
   to merge them into a single array, but you would need to make sure to match up
   all the array elements since they would have different labels for users and posts.
 * All of this would be relatively complex but not impossible – good luck!

Viewing 1 replies (of 1 total)

The topic ‘WordPress Users Search’ is closed to new replies.

## Tags

 * [user search](https://wordpress.org/support/topic-tag/user-search/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [Hugh Lashbrooke](https://wordpress.org/support/users/hlashbrooke/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/wordpress-users-search/#post-16151194)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
