Hi Herve,
Sorry, but there is no straightforward way to do it based on the xprofile data(atleast in 2.9.x version).Regards
BrajeshHello Brajesh
1/ bug
I think there is a bug with the previous proposal
It works well on the list of members.
It also filters elsewhere and especially on the tab my friends.
IF I have 10 friends [5 man and 5 woman] (and that I put that I looked for a woman in my profile), I will see only the 5 women2 / limited profile photo visibility
I want to add a 2nd criterion to not display the profile photos of a member whose value of the numeric xprofile field “photo_priorite” is less than 3.
I found but https://buddypress.trac.wordpress.org/ticket/5839 but I had to make a mistakeWould it be possible to modify the script for these 2 points.
Regards
Hi Herve,
Thank you for the patience.1. I will update it today and post back.
2. Do you want to exclude users from Search or do you just want to hide the profile photo of the user?
Regards
BrajeshThank you for clarifying. I am looking into it.
Regards
BrajeshHi Herve,
Please use this updated code/** * Custom filter for members list for Herve. * * @param BP_User_Query $query query object. * * @return array */ function buddydev_filter_members_list_herve( $query ) { if ( ! is_user_logged_in() ) { return; } $user_id = get_current_user_id(); // get the value for the field. // Use field id for better performance. $searching_for = xprofile_get_field_data( 'I search', $user_id, 'comma' ); if ( empty( $searching_for ) ) { return; } if ( bp_is_user_friends() ) { return;// do not filter on the friends page. It will be problemetic as it won't filter the widget/shortcode on the friends page. } $xprofile_query = isset( $query->query_vars['xprofile_query'] ) ? $query->query_vars['xprofile_query'] : array(); $xprofile_query[] = array( 'field' => 'I am', // I suggest using field id for more efficiency. 'value' => $searching_for, 'compare' => '=', ); if ( bp_is_members_directory() ) { //photo_priorite $xprofile_query[] = array( 'field' => 'photo_priorite', 'value' => 3, 'compare' => '>=', 'type' => 'NUMERIC', ); } if ( ! empty( $xprofile_query ) ) { $query->query_vars['xprofile_query'] = $xprofile_query; } return $query; } add_action( 'bp_pre_user_query_construct', 'buddydev_filter_members_list_herve', 0 );
It will not hide users on friends screen anymore and on the directory, will only list users who have
xprofile field named “photo_priorite” and value set to 3 or above.Regards
BrajeshHello Brajesh
Great 🙂 , it seems to work on the test site.
I need on the production site to create a xprofle field and fill it for everyone to 3 (I mean by sql!?) Because otherwise it does not workSince this is not a member-managed field.
How can I hide this field for members when viewing their profile?Regards
Hi Herve,
You can create a field and set it’s visibility to Admin only. That should most probably help you achieve it.For the data part, i will leave it upto you to handle.
The topic ‘filter the buddypress members in the list of members’ is closed to new replies.