BuddyDev

Search

[Resolved] Filter Directory users via jQuery

  • Participant
    Level: Initiated
    Posts: 16
    Nushara on #28436

    Hey there,

    I am in need to find a way to filter users from the directory. I already have filters in action with a dropdown which is working fine. But I need to find a way to filter them with jQuery.

    I develop a category screen before showing users which then will get filtered by, in my case, categories.

    I have already tried to just select the option from the dropdown to filter them but it looks like that’s not enough. I also found out that there is a cookie set to change it but even after changing the cookie value it’s not working.

    Would be great if you could help me figure out a way to filter users via jQuery so I can use an onClick event.

    Thank you for your time and effort.

    All the best,

    – Mike from Nushara

  • Participant
    Level: Initiated
    Posts: 16
    Nushara on #28442

    So what I have found out so far is it would be something like this:

    
    									$.ajax({
    										type: "post",
    										dataType: "json",
    										url: "/wp-admin/admin-ajax.php",
    										data: { 
    											cookie: 'bp-members-filter%3D<?= $var ?>%26bp-members-scope%3Dall',
    											action: 'members_filter',
    											object: 'members',
    											filter: '<?= $var ?>',
    											user_id: user_id,
    											scope: 'all',
    											page: '1',
    											search_terms: '',
    											template: '',
    											exclude: false},
    										success: function(data) {
    											
    										}
    									});
    

    But it is of course not working. I just thought it would be helpful to make it easier.

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #28449

    Hi Mike,
    Thank you for the question.

    You should be able to achieve it fairly easily.

    May I suggest you to take a look at

    bp_filter_request()
    in the buddypress/bp-templates/bp-legacy/js/buddypress.js

    That should give you the proper idea(You need to use the current cookie etc).

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 16
    Nushara on #28455

    Thank you very much, you were giving me to the right direction.

    What I came out with is:

    
    bp_filter_request('members', '<?= $var ?>', 'all', '#members-dir-list', '', 1, '', '', '');
    

    Which is working fine.

    You have a great day,

    – Mike from Nushara

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #28481

    Hi Mike,

    You are welcome.

    Have a great day to you too!

    Regards
    Brajesh

The topic ‘ [Resolved] Filter Directory users via jQuery’ is closed to new replies.

This topic is: resolved