How to search member directory by user role or the label of the role

I am using the following shortcode to create a member directory. I need to be able to search by the user role and label of the role. The shortcode below always returns no results.

Can anyone help?

Thanks.

echo do_shortcode("

[s2Member-List

link_display_name='$siteURL/author/%%username%%'

levels='3,4,5,6,7,8,9,10,11' 

rlc_satisfy='ANY' 

order='asc'

search_columns='s2member_access_label,role,s2member_access_role'

orderby='last_name' 

enable_list_search='yes' 

/] ");

You need to debug it step by step. Take out everything but one element and try again. If that works, try adding another element … and so on until you identify what’s not working.

Two other points:

  1. Make sure all your members aren’t at levels 1 and 2!
  2. Try swapping your single (’) and double (") quotes. Sometimes that turns out to be crucial.

Hi, so just to test I made it very simple and put the shortcode in a page like this:

[s2Member-List-Search-Box /]
[s2Member-List search_columns=“s2member_access_label” show_fields=“user_email, s2member_access_label” enable_list_search=“yes” /]

The resulting member list does show the Name, Email and Access Level Label for each member.

s2member_level3 is named: “Certified Practitioner”. When I search for this I do not get any results. When I search for “certified” I also do not get any results. All levels above level 3 have ‘certified’ in the label for that level.

Any thoughts on why s2member_access_label does not work with search_columns ?

@AJD, I think this provides your answer: https://s2member.com/kb-article/how-do-i-set-the-s2member-list-field-labels/

Hi, thanks. But that link talks about the label for the fields in the directory itself, which can be set via the s2Member-list shortcode.

However, in general settings > membership levels/labels, you can create labels that are attached to specific membership levels (roles)… so for example, s2member_level1 has a label of “Certified Practitioner” this label is permanently attached to that level.

According to the s2 codex, the labels are stored in the user meta under: s2member_access_label. (http://www.s2member.com/codex/stable/s2member/api_functions/package-functions).

When I use the arg: show_fields=“s2member_access_label” in the Member Directory it outputs this: s2 Member Access Label - Certified Practitioner. This is the expected behavior.

However when I perform a search on the Members Directory by typing “certified practitioner” into the search box, I get no results. So… we can assume that search is not looking in that particular meta for the user. In this case we are supposed to be able to use: search_columns, to indicate additional custom database columns, custom fields, and s2 custom fields that we want to search. However this is not working, or I am using it incorrectly somehow. https://s2member.com/kb-article/s2member-list-shortcode-documentation/

Hmm, I wonder if "s2member_access_label" counts as a custom field, in which case the docs say you’re going to need to use syntax like this: s2member_custom_field_[my unique id]

Hi, thanks. I did try that in a previous version, but went ahead and tried again with the simple shortcode on a page and unfortunately still no luck.

@AJD
AJ,

Unfortunately, you cannot search on the s2Member User Role as the code to do so does not exist.

search_columns If you supply a search keyword (or phrase) these are the wp_users table columns that will be searched. This should be a comma-delimited list of wp_users table columns. The default is ID,user_login,user_email,user_url,user_nicename,display_name. Plus, s2Member will also search (by default) some additional usermeta columns: first_name,last_name,nickname.

Note: It is also possible to search any usermeta field in WordPress; e.g., description, s2member_subscr_id, s2member_subscr_gateway, or any other usermeta field added by a plugin other than s2Member.

Note: It is also possible to search Custom Registration/Profile Fields you created with s2Member. To search custom fields use s2member_custom_field_[my unique id], where you replace [my unique id] with the Unique ID that you gave the field when you created it with s2Member. Please be advised that searching Custom Registration/Profile Fields may result in a slower DB query; i.e., at this time is not recommended on sites with more than 25,000 users.

You can, however, limit the search to specific s2Member User Roles using the roles attribute:

roles Optional. This can be a comma-delimited list of Role IDs (or a single Role ID); e.g., subscriber, s2member_level1, s2member_level2, author, contributor, etc. The default is to include all users. Note: Ordinarily this is set to just one specific Role; i.e., when you want to list users that have a specific Role. However, it is also possible to provide a comma-delimited list of Roles and set rlc_satisfy="ANY" (details below). For instance, if you set roles="subscriber,s2member_level1" rlc_satisfy="ANY" you will list users with a Role of either subscriber or s2member_level1.

I hope this helps.

Hi, thanks. So its not possible to search in the user role. But what about in the Label for the user role? s2member_access_label?