BuddyBoss Home – Web › Support Forums › Themes › OneSocial theme › Show just VENDORS on members page
- This topic has 11 replies, 5 contibutors, and was last updated 7 years, 11 months ago by Alyssa.
Question
April 22, 2016 at 8:40 am #69330@conscious-craftiesHello,
Is there a way for me to only display Vendors on my community page here:
It currently shows customers and other roles, but our community is based around sick and disabled people who love to craft and I’m not sure if our customers are also sick and disabled.
Many thanks,
Karen
Answers
April 22, 2016 at 9:30 am #69346@vapvarunYou can use some custom codes to hide customers and subscribers
https://gist.github.com/sbrajesh/2142009
Regards
Varun DubeyApril 22, 2016 at 7:44 pm #69529@omarobaidDid you manage to do this?
I have tried to put the code, below, together but it is not working
add_action(‘bp_ajax_querystring’,’bpdev_exclude_users’,20,2);
function bpdev_exclude_users($qs=false,$object=false){
//list of users to excludeif($object!=’members’)//hide for members only
return $qs;$excluded_user=join(‘,’,bpdev_get_subscriber_user_ids(),bpdev_get_customer_user_ids());//comma separated ids of users whom you want to exclude
$args=wp_parse_args($qs);
//check if we are searching for friends list etc?, do not exclude in this case
if(!empty($args[‘user_id’]))
return $qs;if(!empty($args[‘exclude’]))
$args[‘exclude’]=$args[‘exclude’].’,’.$excluded_user;
else
$args[‘exclude’]=$excluded_user;$qs=build_query($args);
return $qs;
}
function bpdev_get_user_ids(){
$users = get_users( array( ‘role__in’ => [‘customer’, ‘subscriber’], ‘fields’ => ‘ID’ ) );
return $users;
}April 23, 2016 at 4:14 am #69549@conscious-craftiesHi Omar, was a bit confused by the thread as they made corrections but didn’t put the new code in it’s entirety. I’m very nervous adding code.
I think we need to change the last line:
‘There is a mistake on line 33. It should be return $subscribers not return $users’I also wasn’t sure whether to create a copy of custom_buddypress/bp-functions.php somewhere so it doesn’t get overwritten when we have updates.
Tagging @vapvarun as maybe he can help 🙂
Karen
April 25, 2016 at 2:52 am #69689@vapvarunHi @conscious-crafties @omarobaid
Following should work fineadd_action('bp_ajax_querystring','bpdev_exclude_users',20,2); function bpdev_exclude_users($qs=false,$object=false){ //list of users to exclude if($object!='members')//hide for members only return $qs; $excluded_user=join(',',bpdev_get_subscriber_user_ids());//comma separated ids of users whom you want to exclude $args=wp_parse_args($qs); //check if we are searching for friends list etc?, do not exclude in this case if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$excluded_user; else $args['exclude']=$excluded_user; $qs=build_query($args); return $qs; } function bpdev_get_user_ids(){ $users = get_users( array( 'role__in' => ['customer', 'subscriber'], 'fields' => 'ID' ) ); return $users; }
Regards
Varun DubeyApril 25, 2016 at 7:00 am #69701@omarobaidHi @vapvarun,
Thnanks for looking into this, but it removes everyone and it shows a blank page.
April 26, 2016 at 6:28 pm #69790@conscious-craftiesHello,
Is this where we insert the code @vapvarun:
custom_buddypress/bp-functions.phpWorried about adding this now re Omar’s comment above.
Thank you,
Karen
April 26, 2016 at 7:56 pm #69792@omarobaidYou would actually need to create a new file called bp-custom.php and insert the above code in it.
You would need to put the file here wp-content/plugins
But it didn’t work for me as it removed everyone not just customers.
Let me know if you have a breakthrough
May 1, 2016 at 1:54 pm #69963@rummelhoffThis works better:
<?php add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' ); function buddydev_exclude_users_by_role( $args ) { //do not exclude in admin if( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $args; } $excluded = isset( $args['exclude'] )? $args['exclude'] : array(); if( !is_array( $excluded ) ) { $excluded = explode(',', $excluded ); } $role = 'customer';//change to the role to be excluded $user_ids = get_users( array( 'role' => $role ,'fields'=>'ID') ); $excluded = array_merge( $excluded, $user_ids ); $args['exclude'] = $excluded; return $args; }
May 1, 2016 at 2:28 pm #69965@omarobaidFantastic, thank you very much, It works perfectly.
Do you now how to remove admin as well?
May 9, 2016 at 3:06 am #70213@alyssa-buddyboss
AlyssaParticipant<?php add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' ); function buddydev_exclude_users_by_role( $args ) { //do not exclude in admin if( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $args; } $excluded = isset( $args['exclude'] )? $args['exclude'] : array(); if( !is_array( $excluded ) ) { $excluded = explode(',', $excluded ); } //change 'role' to the role to be excluded $user_ids_customer = get_users( array( 'role' => 'customer' ,'fields'=>'ID') ); $user_ids_admin = get_users( array( 'role' => 'admin' ,'fields'=>'ID') ); $excluded = array_merge( $excluded, $user_ids_customer, $user_ids_admin ); $args['exclude'] = $excluded; return $args; }
May 10, 2016 at 9:05 am #70260@alyssa-buddyboss
AlyssaParticipantThis topic has not been active for quite some time and will now be closed.
Please simply open a new ticket (linking to this one if necessary) if you experience any further trouble, and I’d be happy to investigate further.
Thanks!
- The question ‘Show just VENDORS on members page’ is closed to new replies.