Home › Forums › WP Users Geolocation › Can WP User Geolocation search according to wp profile role?
Tagged: exclude users by role
This topic contains 7 replies, has 4 voices, and was last updated by norfolkandway 2 years, 1 month ago.
-
AuthorPosts
-
February 19, 2015 at 2:57 pm #31610
Can I search users according to their wordpress role with WP Users Geolocation? For example I only want to show wp profiles that have the role of customers only or the role of vendors only.
February 19, 2015 at 11:01 pm #31613Hello Marcsarin,
The feature is not available via UI but you can easily filter Search results ( of GEO my WP’s WP Users form ) based on user role using filters provided by the plugin.February 28, 2015 at 2:48 pm #31612Thanks for the info. I bought the plugin. So how do I filter to show results for vendors role only?
March 1, 2015 at 12:11 am #31611Thank you for the purchase Marcsarin.
Add the code below to the functions.php file of your theme and modify it based on your needs ( the form ID and user role as noted in the script ):
12345678910111213//enable advanced queryadd_filter( 'gmw_ug_advanced_query_class', '__return_true' );function gmw_exclude_users_by_role( $gmw ) {//use the filter only for a specific form. Change the value 1 to your form IDif ( $gmw['ID'] == 1 ) {//Filter results based on Editor role. Modify it based on your needs$gmw['query_args']['role'] = 'Editor';}return $gmw;}add_filter( 'gmw_ug_form_before_users_query', 'gmw_exclude_users_by_role', 10 );February 22, 2016 at 10:56 pm #50816This topic marked “Resolved” due to inactivity. If you wish to reply to this topic please change its status to “Not resolved” before replying.
August 11, 2016 at 2:12 am #53599Sorry for tagging on to an existing thread….
How can we use this code to exclude more than one user role?
August 11, 2016 at 2:24 am #53600I actually meant to show more than one user role (eg show only ‘editor’ & ‘subscriber’ roles but exclude all others).
October 25, 2017 at 4:07 am #56398HI
I am attempting to achieve this on my site –
Submit search result returns only members with role of ‘Vendor’
At present all members that have added their address/location are returned in search results.before I add this code in functions.php can you please tell me
1 – It looks like the code excludes user roles 10
2 – Displays Editor only
In the code
//enable advanced query
add_filter( ‘gmw_ug_advanced_query_class’, ‘__return_true’ );function gmw_exclude_users_by_role( $gmw ) {
//use the filter only for a specific form. Change the value 1 to your form ID
if ( $gmw[‘ID’] == 1 ) {
//Filter results based on Editor role. Modify it based on your needs
$gmw[‘query_args’][‘role’] = ‘Editor’;
}
return $gmw;
}
add_filter( ‘gmw_ug_form_before_users_query’, ‘gmw_exclude_users_by_role’, 10 );I am a bit confused over what this code displays/excludes, Could you please explain?
Thanks
iain -
AuthorPosts
You must be logged in to reply to this topic.