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

Hi. I’ve created a registration/profile field checkbox for users to consent to being included in the membership list. The Unique ID for the checkbox is membershiplist_permission. What code do I put into the membership list page to have only those who have checked the box be included in the list?

I’m thinking that it would be s2If membershiplist_permission="???"

But what would go into the quotes to see the checkbox is checked?

Thanks for any help!!

Keith

I don’t know the answer, but you can find out by:

  1. Create a test Member with the checkbox set and check for the value of that custom field using PHPMyAdmin OR
  2. Experiment. A checkbox is a True/False value. It will most likely be 0 (False)/1 (True). It might also be f/t, n/y, F/T, or N/Y.

I hope this helps.

Sorry, that was an offtopic…

Thanks, I’ve figure that a checked box is “1”. However I cannot, even after hours of experimenting and looking through documents, figure out how to code the search.

All I want to do is use [s2Member-List /] to only include those members how have checked the box and gave permission to be included int the member listing page.

I’ve concluded that the s2If code does not work in this capacity.

I’m guessing that I should be using either s2member_custom_field_[my unique id] or include

Here is the code I’ve thought should work (but does not work).

[s2Member-List levels="4" s2member_custom_field_[membershiplist_permission="1"] show_fields="email,employer_name" orderby="last_name" order="ASC" enable_list_search="yes" /]

Any help is so appreciated!!

Try:

[s2Member-List levels="4" membershiplist_permission="1" show_fields="email,employer_name" orderby="last_name" order="ASC" enable_list_search="yes" /]

Hi. Thanks for your help again. This does not work either. The Member-list page is including all of the users from levels="4" regardless of whether the membershiplist_permission check box is checked or not in their user profile. Any other thoughts?

Could you please try the shortcode with just the membershiplist_permission="1" parameter to see if that filter is processed then? Thanks in advance.

Hi. Thanks so much Pat for reaching out to help me.

I’ve done as you asked, and it appears to not process this filer as there is no difference in appearance between [s2Member-List /] and [s2Member-List membershiplist_permission="1" /].

I guess i need somehow to make a conditional parameter, such as include membershiplist_permission if ="1"

One question. When I use S2Member Pro to create a custom registration/profile field, is the field recognizable in S2Member-List or not? Or do I have to add anything to make the field be recognizable (such as ‘s2Member_membershiplist_permission’ or ‘custom_field_membershiplist_permission’ or something like that? Just so you know, I actually could not find membershiplist_permission anywhere in the database via PHPMyAdmin. How I discovered that if the box is checked the value is “1” by looking at the column in the user profile. When the box is unchecked the “value” is “—”. Could something here be a part of the problem?

Thanks again for your help Pat.

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?