Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Conditional search
This topic contains 2 replies, has 2 voices, and was last updated by unnati 4 years, 1 month ago.
- AuthorPosts
- April 17, 2019 at 4:00 pm #22216
Hi,
I am looking for two different searches according to user login. I have recruiter and Candidate in my user list. So, Recruiter can search for candidate and Candidate can search for a recruiter and HIde their own list from the search.
I know I can create two different searches and exclude the user role. But I want to have the same search which can work with a conditional search on user login.
Attachments:
You must be logged in to view attached files.April 18, 2019 at 8:26 am #22229Hi,
Well, this might be possible via using a custom code, but I am not sure. I did a bit of research, and constructed the custom code below. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
This code will exclude the current users role + the admin user roles. So when testing, if you are logged in as admin, you might not see any results. Please note that there is no guarantee that this will work properly in any case.
Best,add_filter('asp_query_args', 'asp_exclude_roles_sp', 10, 1); function asp_exclude_roles_sp($args) { $user_roles = wcmo_get_current_user_roles(); $args['user_search_exclude_roles'] = array_merge( array('administrator'), $user_roles ); return $args; } function wcmo_get_current_user_roles() { if( is_user_logged_in() ) { $user = wp_get_current_user(); $roles = ( array ) $user->roles; return $roles; // This returns an array } else { return array(); } }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 18, 2019 at 3:45 pm #22255Hi,
The code Didn’t work for me. I end up creating two different search pages and provide a condition on login.
Thanks,
Unnati - AuthorPosts
You must be logged in to reply to this topic.