I need to add user profile to search results for a site we look after. I need to return any user with role of 'Consultant' (and only consultant) whos name or nickname or whatever matches the search request.

You can browse to a consultant page on the site which shows their details but I need it to be included in the search, and am finding it increasingly difficult.

I have tried writing a complex(ish) sql query to fetch out the user id's from the database where the first_name or last_name LIKE '%s%' and where the wp_capabilities is LIKE '%consultant%' which does work to an extend, but I don't know what to do with it now.

Any help is much appreciated.

  • Did you want to create individual user search system for only with user data or just want to include user data in default search stem of the WP have ?
    – mlimon
    Oct 8, 2016 at 18:49

2 Answers 2


If you have a user role called "consultant" and you do a search filtering by capability "consultant", you wouldn't find anything. Roles and capabilities are different things. Here is the codex reference:



You might try using the pre_get_posts filter, along with get_users, to alter the query that's exposed on your theme's search.php.

I'm interested in seeing how this could be achieved, so I've decided to strap on my proverbial rucksack and do some fiddling. If I get anywhere, I'll post my results here.

  • Please do let me know if you find a solution to this. Nov 21, 2014 at 17:11
  • I will! There's quite a lot of threads out there for this same request, but most suggest plugins, so in a pinch, you could go that route.
    – pwbred
    Nov 21, 2014 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.