How to use checkbox to agree to be included in Membership List

Boy, is my face red. I re-read the KB article AGAIN and found that I’d missed a key component of using a Custom Registration Field in the filter/search. You can only use a CRF as a part of the SEARCH parameter and it must be presented like this s2member_custom_field_[my unique id].

Please try:

[s2Member-List search="2member_custom_field_[membershiplist_permission="1"] /]

I was going to give this a quick test, but I keep my site back-ends locked from 2:00 to 6:00 AM.

s2Member Custom Fields are stored in a serialized array in the db_usermeta table. The meta_key is db_s2member_custom_fields. (Note: db here should be replaced by the database prefix used on your WP site.)

Hi Pat. Please don’t be red face, you are very generously helping me out!

I’ve done some more sleuthing. Thank you for the tip on how to find the info in the database. I looked into the test user and have mapped that when the membership permission box is checked, the code meta_value of s:25:"membershiplist_permission";s:1:"1" is added to the wp_usermeta table under the meta_key of wp_s2member_custom_fields.

When the box is NOT checked, the above is deleted (in other words, when it is not checked, the meta_value of membership_permission is removed completely.

I’ve tried out the code you wrote on a clean test page and it did not work: [s2Member-List search="2member_custom_field_[membershiplist_permission="1"] /] However I figured there was a slight error (the s was missing). So I tried out mutiple configurations of the code, none of which worked, as I will write out below:

[s2Member-List search="2member_custom_field_[membershiplist_permission="1"] /]
[s2Member-List search=s2member_custom_field_[membershiplist_permission="1"] /]
[s2Member-List search="s2member_custom_field_[membershiplist_permission="1"]" /]
[s2Member-List search="s2member_custom_field_[membershiplist_permission]" /]

The /] shows up at end of a list of all users, implying that the brackets within brackets is not being recognized as code.

These say “Sorry, there are no users to list at this time” although I have set 3 users with a checkmark. [s2Member-List search=s2member_custom_field_membershiplist_permission /]
[s2Member-List search="s2member_custom_field_membershiplist_permission" /]

I’m not sure what else to check.

Try this:

[s2Member-List search_columns="s2member_custom_field_membershiplist_permission" /]

Hi Tim. That didn’t work. It lists all users regardless of if the profile box is checked or not. It kinda seems like S2Member cannot access the s2member_custom_field.

Try using both search and search_columns. Unless something has changed recently, s2member-profile can definitely search s2Member custom registration fields.

[s2Member-List search_columns="s2member_custom_field_membershiplist_permission" search="2member_custom_field_[membershiplist_permission="1" /]

The syntax needed for this to work as expected is as follows, assuming you created a Custom Registration/Profile Field in s2Member as a checkbox, with a Unique ID of agreed_to_terms.

[s2Member-List enable_list_search="yes" search_columns="s2member_custom_field_agreed_to_terms" search="1" /]

That will display only those users who checked the box. A checked box has a value of 1 in the DB.


Note: Searching for the opposite in this case, will, unfortunately, not work; e.g., trying to list users who did not agree results in a seemingly mysterious set of results.

...  search="0" /] (does not work).

The reasons searching for 0 will not work.

  • By default, PHP considers 0 to be empty, which is the same as not entering a search term at all.
  • Even if we interpret 0 as being the integer value instead of being empty, it would still not work as you might expect. The reason is that internally an unchecked box has no value. Only when the box is checked does an entry appear in the DB that would be searchable.
1 Like

Using the same agreed_to_terms field ID as an example, you can also build conditionals that check for the box being checked (or not). This is accomplished using a combination of our ezPHP for WordPress plugin, and the get_user_field() function that comes with s2Member.

<?php if (get_user_field('agreed_to_terms')) : ?>
   Display content here, the box is checked.
<?php else : ?>
  Whatever you want to show.
<?php endif; ?>

In the opposite…

<?php if (!get_user_field('agreed_to_terms')) : ?>
   Display content here, the box is NOT checked.
<?php else : ?>
  Whatever you want to show.
<?php endif; ?>
1 Like

Jason, it always makes so much sense when you explain things! Thanks!

1 Like

:smile: Thx Tim. I’m just glad I could help.

Thank you so much to everyone who helped!! It worked beautifully. Just in case anyone else if interested in the working code, I’ll list it below. Again- thanks Pat, Tim, and Jason!

The features of this Membership List are:

  • the list is divided by levels of membership
  • I’ve included anchors to jump up and down the list to specific levels.
  • only those members who give permission are included You do this by:
  1. Go to S2Member (Pro)/General Options/Registration-Profile Fields &Options/Add New Field.

  2. Create a “Checkbox (prechecked)”

  3. Make the “Field Label/Description” something like “I agree to my name, email, and place of employment being included in the Membership Listing page (accessibly by logged-in, paid members only).”

  4. Make the “Unique Field ID” this: “membershiplist_permission”

Here is the code for you to use and modify:

The Membership Listing page is viewable by current members only. Inclusion in the list is optional and you can change your preference through your profile. Inappropriate use of members emails will not be tolerated.

  [s2Member-List-Search-Box action="" placeholder="Search Members..." /]
<hr>
<a name="flmb"></a>
</a>Jump down to <a href="#stmb">Student Members</a> | <a href="#rtmb">Retired Members</a> | <a href="#afmb">Affiliate Members</a>

<h2>Full Members:</h2>
[s2Member-List enable_list_search="yes" levels="4" search_columns="s2member_custom_field_membershiplist_permission" search="1" show_fields="email,employer_name" orderby="last_name" order="ASC" /]
<hr>
<a name="stmb"></a>
<h2>Student Members:</h2>
[s2Member-List enable_list_search="yes" levels="1" search_columns="s2member_custom_field_membershiplist_permission" search="1" show_fields="email,employer_name" orderby="last_name" order="ASC" /]
<hr>
<a name="rtmb"></a>
<h2>Retired Members:</h2>
[s2Member-List enable_list_search="yes" levels="3" search_columns="s2member_custom_field_membershiplist_permission" search="1" show_fields="email,employer_name" orderby="last_name" order="ASC" /]
<hr>
<a name="afmb"></a>
<h2>Affiliate Members:</h2>
[s2Member-List enable_list_search="yes" levels="2" search_columns="s2member_custom_field_membershiplist_permission" search="1" show_fields="email,employer_name" orderby="last_name" order="ASC" /]

</a>Jump up to <a href="#flmb">Full Members</a> | <a href="#stmb">Student Members</a> | <a href="#rtmb">Retired Members</a>
1 Like

Ok, one more issue :slight_smile:.

The search form box does not work at all. Yesh. I’ve experimented and no matter what, it says there are 0 results in each of the level categories. In the address bar it says "www.--------.com/membership-listing/?s2-s=Jane+Doe

Perhaps that is a clue as to why the search form it isn’t working?

I’ve been trying to solve why the search box is not working. Strangely, if I try to search for “1” or “0” then the search box returns with all members! Could it be because I used search_columns in the S2Member-List code? If I search for a name of anysort, then it comes back as zero.

Is there some shortcode that I should include in this line: [s2Member-List-Search-Box action="" placeholder="Search Members..." /] that makes the search function work?

Hi Keith.

Did you resolve this. I’m trying to do the same thing and finding that the custom field can’t be used as a filter along with another filter for member fields (custom or otherwise!)

Andy

Andy (and Keith). I used the radio-button-multi-option to solve this same need without using PHP The question prompt reads “I want to be in the directory” and the options are yes and no. using the pipe | allows the webmaster to choose both the option value (what you will use to filter behind the scenes) and the “option label” (what the user sees when they choose which box (really circle) to check. HERE IS THE PART that makes no sense, but MAKES IT WORK: the software needs to have a ccaps filter, even if you add in all your ccaps so it doesn’t limit the output.

[s2Member-List orderby=“last_name” order=“asc” s2member_custom_field_directory_public search=“public-directory” show_fields=“Name:full_name,last_name, email, phone,phone2, city” limit=“100” ccaps=“annual,lifetime,autorenew,executive” rlc_satisfy=“ANY” avatar_size=90 /]

But Jason @jaswrks , can you tell me why my output will not orderby?

@daleandy, @MASP

Hi MCBA

I have to say that I admitted defeat on the basis that it is too hard to achieve in S2Member with the limitations of the functionality. Instead I installed plugin “AMR Users” which integrates with S2Member custom fields and presents a public directory. It worked perfectly and with greater options and functionality than I’d originally required.

It does however mean that I do not need the Pro licence, but that’s life. J

Thanks, @daleandy ! I will check out AMR Users. I have S2Member Pro on two sites, helping two non-profits with over 1,000 members. I’m hoping that @jaswrks can straighten me out on the orderby and search of that list (right now the search pulls from entire data base instead of just the custom_field search.)

I shall watch this thread to see whether you get a solution, but I went thought the exact same issues and came up blank. What you in effect want is the custom field to be treated like a ccap field, but S2Member treats them very differently.

Took me an hour to get AMR Users to do what I wanted. Don’t get me wrong, S2Member is great and a key part of my social group site functionality, but it has been hard to get the member directory issue resolved, and interfacing seamlessly with mailchimp took a lot of code in a S2hacks MU plugin.

Good luck.

Andy

@daleandy Andy, which AMR additional plugins did you buy?

AMR Users. Free version was fine to do a good member directory integrating with the S2Member custom fields.

@daleandy Thanks or finding AMR plug-in for me. I am playing with AMR now. I need filtering, which requires +plus addon, unless, as AMR suggests, I may be able to get away with an HTML filter, if I can figure it out.

FROM THEIR WEBSITE:
Simple Filtering
If you have some very simple filtering needs, you could code your own little form html to sit on the same page. The html should pass the following parameters back to the user list page.
Yes – this can also be done as links from other pages.

QUERY STRING PARAMETERS:
filter=hide or show
activate filtering request. plugin will then look for column names
hide says “hide that column” – as all rows will have the same value
show = “show the column”
column_name=value
pass the technical column name (see the ‘nice names’ list in the settings) and the value to be selected