I am working on a membership site which requires a front-end user search. I have been searching for an answer like a mad man, and I could really use some help! While there are several plugins that have this capability (WordPress Members List, AMR Users, etc.); none of them do exactly what I need, and by looking at their source codes, would be a huge mess to pick apart, and seems like it might a fruitless effort in the end anyway. I fully realize that I will likely need to write something custom myself here. The logic I need is actually very straight forward and simple in terms of how it needs to work.

User search logic goes like:

1. User enters another users USER ID # into a simple single search field.

2. Upon submitting search, the user is taken directly to the members profile

Yes, users will search for other users by their user ID (think of it as a membership number). There is a specific reason for this, which does make sense for the site. But I don’t want to get off the subject, just know that this requirement cannot be changed. I am thinking this shouldn't matter though, because if you can query “user_nicename” from the “wp_users” table in the database, you should be able to query the “ID” field as well?

I do not expect anyone to provide me with the entire code for this obviously, but it would be nice if you could give me some general direction (and perhaps examples if possible) on how I can go about this. I am having a difficult time wrapping my head around this for some reason.


2 Answers 2


As you haven't offered the details on what you're after, I'll try to grab them all very briefly.

Use the API - public WP_User_Query API functions

Basically get_user_by() should be enough for you. Let's say you fire of your form and the input field name was user_id. So you'd just retrieve the value from the $_REQUEST (or $_GET) and then do a simple query.

$user = get_user_by( 'user_id', $_REQUEST['user_id'] );

Advanced Task: Meta User Query

If you're going to do more complex requests (for maybe only a partly request that covers more than one user as possible result), then it's time to call get_users(), which is the default API wrapper for new WP_User_Query.

A meta query could look like this:

$args = array(
    'meta_key' => 'custom-usermeta',
    'meta_value' => $cat_id,
    'meta_compare' => '='
$users = get_users( $args );

AJAX Search

If you need AJAX search functionality, just take a look at the answers filed under to get around it - no reason repeating it here.

I have asked a question about autocomplete some time ago and covers the most important parts.

// jQuery autocomplete - already bundled with WP core
function wpse71343_scripts()
    wp_enqueue_script( 'jquery-ui-autocomplete' );
add_action( 'wp_enqueue_scripts', 'wpse71343_scripts' );
  • Thanks. Your first example using get_user_by sounds like what I am looking for. One of the biggest things that is confusing me is typically when creating a search you would create a results page which is the form action, that also contains the code which processes the request. So how do I exactly go about doing that when there is no results page? The result is just the users profile. I'm not understanding how to format the query. Thanks for your help!
    – CSteel
    Nov 6, 2012 at 17:09
  • @CSteel There're plenty of answers about how to modify the query by using the filters (post_request, posts_clauses, etc). Those will show you how to $wp_query->set() what you need for specific pages (like the user results page and above args). Or you can simply query them in your template.
    – kaiser
    Nov 7, 2012 at 10:31

I think the WordPress function you're looking for is:

Of course you'll have to generate the page with the results returned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.