BP Profile Search › excluding users from search
-
AuthorPost
-
Vasily
GuestDear Andrea,
Can I exclude some users from searching? The idea is that those users who pay for participation will be in search, and those who do not pay will be excluded. Maybe I should use the plugin s2members?
Sincerely
Vasilyandrea
Plugin AuthorHi Vasily,
How can you tell if the user is a paying member or not? Is that info stored in a profile field, in a role, or otherwise?
Vasily
GuestGood question. I agree with you. While there is no such information. I just know who paid and who did not.
andrea
Plugin AuthorIf you store that information in a profile field with value, say, ‘paid’, you can build a directory of paying members with this shortcode:
[bps_directory field_47='paid'](replace 47 with the actual ID of your profile field)
Then you can select that directory as the results page of your search form, and you’ll get the search restricted to paying members.
Vasily
GuestNice, and thank you! But the users could change this profile field manually and appear in the search again I set the visibility only for me, but the user can change this value.
andrea
Plugin AuthorYou are right, that won’t work!
You can use the member type instead. Build a directory of paying members with this shortcode:
[bps_directory member_type='paid'](replace paid with the actual member type you give to paying members)
Then you can select that directory as the results page of your search form, and you’ll get the search restricted to paying members.
Please let me know if this works for you!
Vasily
GuestFor the site, I used BuddyPress Member Type Generator. There several types of users: Companies, Restaurants, Users, etc. Every user can be only one type of users.
Does it mean that I need to create 2 of the additional types instead of the current one?
For example: “Paid companies” and “Unpaid companies” instead of “Companies” and choose the right type for every company (depend on payment status)?
Sincerely
Vasilyandrea
Plugin AuthorIf you are already using member types for another purpose, I wouldn’t use them to also store the payment status.
I’d go back to using a profile field, adding a plugin to prevent user modifications to that field. If you prefer, you could also use this quick and dirty code in bp-custom.php:
add_action ('bp_members_admin_load', 'prevent_profile_field_update'); add_action ('wp', 'prevent_profile_field_update'); function prevent_profile_field_update () { if (!bp_current_user_can ('bp_moderate')) { $ID = 27; if (isset ($_POST['field_ids'])) { if (is_array ($_POST['field_ids'])) foreach ($_POST['field_ids'] as $k => $ids) $_POST['field_ids'][$k] = implode (',', array_diff (explode (',', $_POST['field_ids'][$k]), array ($ID))); else $_POST['field_ids'] = implode (',', array_diff (explode (',', $_POST['field_ids']), array ($ID))); } } }Replace 27 with the ID of the field that users aren’t allowed to modify.
Vasily
GuestA lot of thanks, Andrea!
I found BuddyPress Non Editable Profile Fields plugin
So, I need to return to your first advice.
andrea
Plugin AuthorYes, I think that’s a good solution.
Please let me know if everything works for you!
Vasily
GuestYes, it works for me. A lot of thanks!!!
andrea
Plugin AuthorYou are welcome, all the best with your site!
Vasily
GuestVery nice and thank you!
Andrea, could you give me your e-mail? Maybe I can help you?andrea
Plugin AuthorSure, I’ve just sent you an email. You can use that email address to contact me or, if you prefer, my Contact page.
-
AuthorPost