Tagged: badges, BuddyPress User Badges
Is it possible with the badges plugin that in searches the badged user will come up first e.g. search for someone that prints business cards, the member with a badge will come up first?
Thanks for your help
Mark
Hi Mark,
Thank you for the question.
It might be doable. I will need couple of days before I can check it and post some code.Thank you
BrajeshTHanks so much thats amazing. Cheers for this, please let me know if I can help in any way. Have a great weekend. 🙂
Hi Brajesh
Just seeing if you had any luck with this feature.
Thanks for looking into this.
Hello Mark,
Please try the following code in your bp-custom.php file. It will list members with most badges on top.
add_filter( 'bp_has_members', function ( $has_members, $members_template ) { if ( ! $has_members || ! function_exists( 'bp_user_badges_get_user_badges' ) ) { return $has_members; } if ( ! bp_is_members_directory() ) { return $has_members; } usort( $members_template->members, function ( $first, $second ) use ( $members_template ) { if ( count( bp_user_badges_get_user_badges( $second->ID ) ) >= count( bp_user_badges_get_user_badges( $first->ID ) ) ) { return 1; } return -1; } ); return $has_members; }, 10, 2 );
Let me know if it works or not.
Regards
RAviHi This is throwing
There has been a critical error on your website. Please check your site admin email inbox for instructions.
This is the layout of my bp-custom.php file in plugins
<?php
add_filter( ‘bp_docs_get_default_access_options’, ‘my_change_docs_default_access_levels’ );
function my_change_docs_default_access_levels( $defaults ) {
$defaults[‘read’] = ‘loggedin’;
$defaults[‘edit’] = ‘creator’;
$defaults[‘read_comments’] = ‘loggedin’;
$defaults[‘view_history’] = ‘creator’;
return $defaults;
}/*allowing badges to be shown first in the searches*/
add_filter( 'bp_has_members', function ( $has_members, $members_template ) {if ( ! $has_members || ! function_exists( 'bp_user_badges_get_user_badges' ) ) {
return $has_members;
}if ( ! bp_is_members_directory() ) {
return $has_members;
}usort( $members_template->members, function ( $first, $second ) use ( $members_template ) {
if ( count( bp_user_badges_get_user_badges( $second->ID ) ) >= count( bp_user_badges_get_user_badges( $first->ID ) ) ) {
return 1;
}return -1;
} );return $has_members;
}, 10, 2 );
?>I have another function at the top. Im also using the plugin bp profile search. Which I think uses filters, could this be the problem?
No problem at all thanks so much for your help. This is a really great feature.
I still get the same error after removing the ‘?>’
How can I check the error logs. Little new to this bit.
Regards
Mark
Hi Mark,
Please share the complete code from your bp-custom.php(all content from the file including tags).
You can put it on pastebin.com and link me. That will help us assist you quickly.Regards
Brajesh
You must be logged in to reply to this topic.