BP Profile Search › Conditional Hidden Filters for Members Directory
-
AuthorPost
-
Max
GuestHello!
I’m building a dating site and I want male users to see female users in members directory by default and vice versa.
I have tried the most acceptable solutions and none work on my site sadly.
I tried:https://gist.github.com/anonymous/7913816
https://wordpress.org/support/topic/filtering-buddypress-widgets-by-gender/
I got an idea after to maybe use a conditional hidden filter.
(if current user has field_sex =”male”, then hidden filter field_sex = “female”)
(if current user has field_sex =”female”, then hidden filter field_sex = “male”)My question may be a bit dense as I have no programming background, but I’ll be very delighted to get a solution to this problem.
Thanks a lot
andrea
Plugin AuthorHello Max,
Your idea can be implemented adding this code to your bp-custom.php:
add_filter ('bps_hidden_filters', 'my_hidden_filters'); function my_hidden_filters ($filters) { $user_id = bp_loggedin_user_id (); if ($user_id != 0) { $gender = xprofile_get_field_data (247, $user_id); if ($gender == 'Male') $filters['field_247'] = 'Female'; else if ($gender == 'Female') $filters['field_247'] = 'Male'; else $filters['field_247'] = ''; } return $filters; }Replace 247 with the actual field ID of your Gender field.
-
AuthorPost