I have custom fields setup in S2MemberPro, lets say they are these:


I want to search the custom fields if searching those fields, and if searching the normal fields like these:


those are the normal fields that are in Wordpress, so I assume they are in two different locations.

So using PHP, in my search query, what would I search for?

I tried this:

$_searchedWhat = $_REQUEST['field'];
$_searchedFor = $_REQUEST['search'];
echo "Searching the " . $_searchedWhat . " fields for " . $_searchedFor . "...<br />
<br />";
$tusers = get_users( array( "search" => $_searchedFor ) );

// also tried it this way:
$tusers = get_users( array( "$_searchedWhat" => $_searchedFor ) );

// Array of WP_User objects.
foreach ( $tusers as $user ) {
    echo "Id: " . $user->ID . " - Member Username: " . $user->user_login . " - Member Name: " . $user->first_name . " - Member Lastname: " . $user->last_name . " - email: " . $user->user_email . '<br />';

those did not work, except if I searched for email. If I searched for email, the first one worked.

So, is there a way to search both tables where the custom_fields are stored for all the members with that data in the field I'm searching?

What I echoed there, was just for the testing of it. I'll have it output something useful that I'm doing this for.


Probably this plugin is using user_meta table. Your query should looks like this:

$args = array(
    'meta_key' => $_searchedWhat,
    'meta_value' => $_searchedFor

$users = get_users($args);

For more informations look into documentation: get_users

EDIT: Unfortunately, that plugin is storing all data into one field, so you cannot query users by single field. You should use custom fields in posts or create own meta boxes with inputs that will store each field separately.

  • I went and looked, it looks like they are in these field: wpth_s2member_custom_fields all have the same meta_key field but the data is in that wierd dotNotation that wp uses: a:10:{s:10:"first_name";s:3:"Jimmy";s:9:"last_name";s:6:"Carson";s:11:"referredby";s:3:"100";s:5:"phone";s:14:"(405) 463-6182";s:14:"street_address";s:11:"1611 E. 7th";s:15:"street_address2";s:0:"";s:4:"city";s:8:"Boise";s:5:"state";s:2:"ID";s:3:"zip";s:5:"00000";s:7:"country";s:13:"United States";} The search I did for: "city" and searched for "Boise" did not result in any records, so what what would work? – Richard Jones Jul 26 '16 at 13:10
  • This notation is creating, when array is saved into meta table (PHP serialize function). I will change my answer to fit into this. – Krzysztof Grabania Jul 26 '16 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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