Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Including user roles when do user search
This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko 2 years, 5 months ago.
- AuthorPosts
- December 9, 2020 at 3:14 pm #30599
Hello,
Simple question:
In the User Search tab of General option we have a box for choosing user roles to exclude from search. But it isn’t good enough for us. We need something for including user roles in search. Why? Because, if we have some user in two roles and one of them excluding user and one including, the user will be excluded what is wrong in our case. So, we need some box (or choosing option for include/exclude from user roles)
Any suggestion?
regards,
ZarkoDecember 9, 2020 at 4:16 pm #30602Hi Zarko,
Well, there is no option for that, but you can try using the asp_query_args filter to maybe use a programmatical solution to filter by user meta.
Try something like this:
add_filter("asp_query_args", "asp_query_args_change", 10, 2); function asp_query_args_change($args, $search_id) { // Roles list $roles = array('role1', 'role2'); global $wpdb; $args['user_meta_filter'][] = array( 'key' => $wpdb->base_prefix."capabilities', 'value' => roles, 'operator' => 'IN', 'allow_missing' => false ); return $args; }
Add the roles to the $roles array variable. I could not test this code, so please be careful, read the safe coding guide.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
December 9, 2020 at 8:25 pm #30606Ok, I’ll try with this filter, but maybe it will be wise to think about including this feature into plugin. 😉
December 15, 2020 at 1:18 pm #30696I’ve just tried your code, but doesn’t work!
When it’s applied no user is searched out. Are you sure that’s code is OK? (because I found some typos)add_filter("asp_query_args", "asp_query_args_change", 10, 2); function asp_query_args_change($args, $search_id) { if ($search_id == 2) { // Roles list $roles = array('um_clanovi-udruge'); global $wpdb; $args['user_meta_filter'][] = array( 'key' => $wpdb->base_prefix."capabilities", 'value' => $roles, 'operator' => 'IN', 'allow_missing' => false ); } return $args; }
December 15, 2020 at 2:02 pm #30703I think it might be the wrong operator. Try “LIKE” instead of the “IN”:
'operator' => 'LIKE',
I’m 99% sure that is going to help.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
December 15, 2020 at 2:35 pm #30706Yea! Now works!
Thanks for quick response.
Great plugin, worth that money! 🙂
December 15, 2020 at 2:37 pm #30707You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.