S2Member field integration

BP Profile Search S2Member field integration

  • Author
    Post
  • #10345 Reply
    Christopher
    Guest

    Good afternoon all,

    I’ve seen a couple of old topics that mention integrating S2Member fields into Profile Searches. Several mention a tutorial that someone intended to publish, but I can’t find it anywhere. Are there any instructions on accomplishing this?

    Specifically, I’m looking to get the s2member_access_label as a drop-down selection in the search.

    Thank you!

    #10346 Reply
    andrea
    Plugin Author

    Hi Christopher,

    The documentation to add any member-related information to BP Profile Search forms is not ready yet, but in the meantime I can answer your, or your developer’s, questions.

    Of course I’ll be able to explain the BP Profile Search API, not something related to s2Member.

    #10347 Reply
    Christopher
    Guest

    Thank you Andrea,
    I do some small scale work in WordPress (mostly child themes), and while I’m comfortable in HTML and CSS I only work with the simplest of PHP. I have been modifying the Buddypress templates, so would be comfortable modifying BPS templates as well, but I’m unsure of what exactly the modified code should be.

    What I want to do is to fetch user data stored in a non-Buddypress table and use that as the selection options in either a drop-down (single selection) or radio button (multiple selection) search.

    I know I can get that user data with WP’s get_user_meta function or with one of S2member’s functions, but I don’t know how to integrate that function into a modified Search template.

    I completely understand not being able to comment on another plugin’s API, so if it’s easier for you then we can just use get_user_meta since that’s a WordPress function.

    Thank you again!

    #10349 Reply
    andrea
    Plugin Author

    Hi Christopher,

    If the data you are interested in are stored in the usermeta table, you can easily add that search field to BP Profile Search forms, see:

    https://dontdream.it/bp-profile-search-4-8-4/

    #10351 Reply
    Christopher
    Guest

    Thank you! This is very close to what I need.
    The last piece of the puzzle is that we use specific names for our user roles based on people’s function within our organization. If I were to add a key for user_level (which returns a numerical value), is there a way to then change those numerical values into the role names we use and populate the search with those?
    Thank you again for your time and consideration,
    Chris

    #10352 Reply
    andrea
    Plugin Author

    Yes, if you refer to the above post:

    https://dontdream.it/bp-profile-search-4-8-4/

    where the example options are:

    $options = array (0 => 'Male', 1 => 'Female');

    the keys 0, 1, … are the values stored in the database, and ‘Male’, ‘Female’, … are the labels you want to see in the front-end. You can simply adapt the array to your use case.

    #10354 Reply
    Christopher
    Guest

    Oh yes, I figured that out after I wrote you but got called away before I could respond again to let you know.

    I’ve implemented the changes using the code

    $options = array (1 => ‘Associate’, 2 => ‘Youth’, 3 => ‘Basic Actor/Combatant’, 4 => ‘Intermediate Actor/Combatant’, 5 => ‘Advanced Actor/Combatant’, 6 => ‘Fight Instructor’, 7 => ‘Fight Director’, 8 => ‘Fight Master’, 9 => ‘Maitre d\’Armes’, 10 => ‘Honourary’);
    $keys[‘wp_y8gu9p_user_level’] = array (‘numerical’, $options);

    And then added an ‘is one of’ search to my form, but when I run the search it returns no results, so matter which or how many radio buttons I check. (I currently have a user list that has 5 sample users of different levels, and I’ve confirmed the numerical values in user_meta). I’ve also tried it with an ‘is’ search, and it still returns no results.

    #10355 Reply
    Christopher
    Guest

    Ignore the code block above. The actual code that I am using is:

    $options = array (1 => ‘Associate’, 2 => ‘Youth’, 3 => ‘Basic Actor/Combatant’, 4 => ‘Intermediate Actor/Combatant’, 5 => ‘Advanced Actor/Combatant’, 6 => ‘Fight Instructor’, 7 => ‘Fight Director’, 8 => ‘Fight Master’, 9 => ‘Maitre d\’Armes’, 10 => ‘Honourary’);
    $keys[‘wp_y8gu9p_user_level’] = array (‘text’, $options);

    #10356 Reply
    andrea
    Plugin Author

    Hi Christopher,

    Your code looks good to me.

    If you can send me a WP admin access to your test site, I’ll take a closer look (use my Contact page to share it privately).

    #10363 Reply
    andrea
    Plugin Author

    For other interested readers, it’s possible to search by s2Member membership levels as follows:

    1. Add roles (under Usermeta data) to your search form;

    2. Add this code to your bp-custom.php file:

    add_action ('bps_edit_field', 'set_role_names');
    function set_role_names ($f)
    {
            if ($f->code == 'roles')
            {
                    $f->options = array ();
                    $f->options['s2member_level1'] = 'Your label for the 1st level';
                    $f->options['s2member_level2'] = 'Your label for the 2nd level';
                    $f->options['s2member_level3'] = 'Your label for the 3rd level';
    
                    // and so on ...
            }
    }
Reply to: S2Member field integration
My Information