BuddyDev

Search

[Resolved] Page that shows only user with specific profile field value

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45741

    Hello,

    I try to show on a page only users with a specific profile field value, I want to have the same view as the member page but only for specific users.

    For example we can imagine that we have 9 users and 3 teams with 3 users in each.

    In their profile, they have a field called “Team” and the value is 1, 2 or 3.

    Then I want to create a page that shows only users from team 1 with same view than the member page but filtered on the field “Team” with the value “1”.

    Is it possible to do such thing ? I tried but didn’t find any solution to solve that.

    Thank you for your help.

  • Keymaster
    (BuddyDev Team)
    Posts: 21466
    Brajesh Singh on #45753

    Hi Lobo,
    Thank you for the question.

    1. Do you mean same view as members directory page? You may want to check the BP profile search plugin and see if it supports this?

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45770

    Hello @Brajesh Singh,

    I got an eye on this plugin but that’s not what I need, this plugin permit to do a search form for searching in a field and then showing those members.

    Me i just want a page with a shortcode showing directly members who has a specific value in a field.

    and I will create one page for each value of this field.

    So in the example given before, on page for users from team 1, one page for users from team 2 and one for users from team 3.

    Don’t want any user interaction for that, just showing automatically members who has this value in this field.

    It’s just like a SQL Query like that :

    SELECT * FROM users where Team=1

    And I want this to show all users from team 1 like the member page does.

    Thank you πŸ™‚

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45771

    I found this code to create a function that will filter based on the field value :

    function my_custom_ids( $field_name, $field_value = ” )

    I fount it here : https://codex.buddypress.org/developer/loops-reference/the-members-loop/

    I understood I need to add this code in my-theme/functions.php or in bp-custom.php but after that how can I call this function on the 3 different pages with the 3 different fields values ??

    The code on the three pages will be like that if I understood well :

    <?php if ( bp_has_members( my_custom_ids( ‘Team’, ‘1’ ) ) ) : ?>
    <?php if ( bp_has_members( my_custom_ids( ‘Team’, ‘2’ ) ) ) : ?>
    <?php if ( bp_has_members( my_custom_ids( ‘Team’, ‘3’ ) ) ) : ?>

    I missed something, I really don’t know where to put the code that call the created function on the new page I created :/

    Thank you for your help

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45801

    Any help on that please ?

  • Keymaster
    (BuddyDev Team)
    Posts: 21466
    Brajesh Singh on #45802

    Hi Lobo,
    If your goal is to search and list via xprofile fields, you may want to copy the members-loop.php and then change

    
    if ( bp_has_members( bp_ajax_querystring( 'members' ) ) ) :
    

    with

    
    if ( bp_has_members( array('xprofile_query' => array(
    	array(
    		'field' => 1,
    		'value' => 'Some Name',
    
    	),
    ) )) ) :
    
    

    in the copied loop. Update the field id and the value as you need and it will list the members for you.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45814

    Hello,

    Thank you for the code, but the problem is that I also want to keep the actual member’s page and add 3 other with the modified code and don’t know where to put the modified code.

    I need 3 different pages with 3 different values.

    If I create a page, I don’t know where and how to call the modified loops for a specific page…

    Thank you

  • Keymaster
    (BuddyDev Team)
    Posts: 21466
    Brajesh Singh on #45822

    Hi Lobo,
    I was not suggesting to change your main loop. I was suggesting to create multiple loops.

    We lack the time to provide custom code for your specific need currently. I or my team will be glad to offer you a shortcode(without any customization of the layout) in hopefully couple of days or week when we have a bit low workload.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45827

    Okay,

    Thank you for that I understand perfectly.

    No problem I can wait a little bit for your help πŸ™‚

    Thank you so much

  • Keymaster
    (BuddyDev Team)
    Posts: 21466
    Brajesh Singh on #45841

    Thank you.

You must be logged in to reply to this topic.

This topic is: resolved