BuddyDev

Search

filter the buddypress members in the list of members

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #13131

    hi

    Thank you

    For sorting on a numeric field linked to the profile of a member, is there another way to sort?
    knowing that the theme only loads about twenty profiles at a time

    Regards

    • This reply was modified 6 years, 2 months ago by Hervé.
  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #13148

    Hi Herve,
    Sorry, but there is no straightforward way to do it based on the xprofile data(atleast in 2.9.x version).

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #13719

    Hello 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 women

    2 / 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 mistake

    Would it be possible to modify the script for these 2 points.

    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #13771

    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
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #13788

    Hello Brajesh
    I want to exclude these people from a member’s search results, with this criterion
    Good day
    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #13791

    Thank you for clarifying. I am looking into it.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #14002

    Hello Brajesh
    little reminder
    Thank you

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #14097

    Hi 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
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #14111

    Hello 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 work

    Since this is not a member-managed field.
    How can I hide this field for members when viewing their profile?

    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #14122

    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.

This topic is: not resolved