Posted on

User profile search

Relevanssi Premium can search user profiles. So far the following data gets indexed from user profiles: first name, last name, display name and description. If you’re interested in having something else indexed, there’s an option in the options page.

Because WordPress only handles posts in the search result pages, Relevanssi must make WordPress believe it’s getting posts, even though it gets user profiles. This causes some problems, which are fortunately fairly easy to fix with some changes to search results templates.

Some problems are already taken care of. Relevanssi contains a filter that should fix the_permalink() for user profiles.

It’s easy to recognize the user profiles. You can test the value of $post->post_type, it’s ‘user’ for user profiles.

To make things slightly easier, there’s a filter hook. You can add a filter to ‘relevanssi_user_profile_to_post’ to make changes to the post object created from user profile. It has the basic values already set.

  • lesteph

    Would be great to be able to specify additional user profile fields to index – I’m replacing the Jabber field with a field for the user’s Organisation, and want to be able to run searches to return items contributed by users from a particular organisation.

    Currently, looks like I’ll have to move that into a custom taxonomy of its own to be able to make it searchable in Relevanssi, is that right?

    • I could add an option to list the fields to index (or to index all fields). I can make the change in the next version.

      If you want to make a quick fix for it, see how description is handled in relevanssi_index_user() and copy that for any fields you want to index.

  • Jens Wedin


    I don’t really understand what I need to be able to search for user profiles? Could you please add some code examples?


    • 1. Set up the options so that user profiles are being indexed.
      2. Re-index.
      3. That’s it.

      You may need some changes to your search results template, particularly if you’re using the_content(). the_excerpt() and the_permalink() should, however, show correct information.

      • Jeff

        It just doesn’t work if all you do is change the options and re-index.

  • Ravishankar Ayyakkannu

    I bought your plugin recently and I am very much frustrated. When i searched for a user’s name,its showing “Sorry, no posts matched your criteria” or It display the list of posts. When i click the users name in search result, it redirects me to the home page. I am using buddy press. I would like to display users profile pic and his name in search result. Please explain me on this.

    • Relevanssi may or may not be compatible with BuddyPress; I don’t know, I’ve never tested, and certainly no BuddyPress support is promised. Are those users regular WordPress users? If so, they should be searchable.

      To display profile pictures, you need to edit your search results template to show whatever you want. User profiles have $post->post_type “user”.

  • Hello. @ Ravishankar Ayyakkannu, if you want a buddypress plugin that searches user profiles, perhaps you should try a plugin called “BP Profile Search” (without tha quotes)

    I hope it works for you.

    @ Mikko Saari, please i am still expecting response to the email i sent you. Thanks.

  • Tom White


    I am trying to set up just user profile search and so only have that option checked on the options page.

    When I click on build the index I get Warning: Invalid argument supplied for foreach() in /home/smallbu3/public_html/ on line 2723

    I would like just User Profile Pages to be indexed in search results.

    • Hmm, that line checks the user capabilities to see if that user is a subscriber. For some reason the user doesn’t have any capabilities. Are you using some custom systems?

      Anyway, getting only user profile pages indexed is a bit tricky.

      • I am also looking for only user profile pages to be indexed. I have the option of setting up a custom results page.

        • Actually, it’s fairly simple. Use ‘relevanssi_do_not_index’ filter to block everything from index. Just add a function on the hook that always returns true. The filter doesn’t apply to user profiles, so that’s what gets in the index.

  • Hi,
    I’m looking for a way to search for user metadata on an intranet.
    For example, I’ve added a ‘certifications’ field as user metadata, and that field displays on the Author page for the user. I need the ability for someone to type in a certification in a search box and return either a list of users or author pages that have that certification.
    Is this something this plugin can do?
    Will it handle partial matches, rather than matching the whole field?

    • Yes, this should be possible. Relevanssi can index user meta fields. It will handle partial matches, yes.

  • Foo

    can you confirm me that with the premium version I can search users filtering with multiple custom user meta fields?
    For example, if implemented custom user meta fields, like age, sex and hobby,
    I need to search users with age: 18, sex: male, hobby: chess…

    Thanks 😉

    • Yes, that is possible, but to do filtering like that, you need some extra programming with the relevanssi_hits_filter.

  • Is it possible to give the user post type a weight? I’d like to weigh it higher than other post types.

    • Yes, though not directly from settings (that’s something I could well add, by the way). Use something like this:

      add_filter(‘relevanssi_match’, ‘add_weight_to_users’, 10, 2);
      function add_weight_to_users($match, $idf) {
      if (substr($match->doc, 0, 2) == ‘u_’) {
      $match->weight = $match->weight * 10;
      return $match;

      • Thanks a lot. It works great.

      • I have another question. I’d like to only index users that have the Author role. I needed this done quickly, so I modified the get_users variable on line 877. However, since I don’t want this overwritten with future updates, is there a better way to do this?

        • Yes. You can use ‘relevanssi_user_index_ok’ filter. It has a boolean value as a parameter and the user object as an additional argument. You can write a function that checks the user role and if it’s not Author, return false.

  • Abdul Mannan

    I have read that we are able to add an additional column to the search for the user. But don’t know how exactly i can achieve that. I have an additional meta value in the user meta i.e Company Name and i want it to include in the search as well. Can you please explain a bit or share the link from where i can get the help regarding this.

    • It is a simple setting in Relevanssi Premium. If you don’t use Relevanssi Premium, you can’t index user profiles in the first place.

      • Abdul Mannan

        Thanks for the quick response Mikko. Yes i am using the Relevanssi Premium.

        I am able to see this option in the admin panel “Extra user fields to index:” Should i mention there the comma separated Meta Keys and it will look in the usermeta table ?

        • Yes, that’s it.

          • Abdul Mannan

            Thanks Mikko for such a nice plugin. Let me give it a try and will let you know if i will get stuck somewhere 🙂

  • Abdul Mannan

    Hi Mikko. I have another quick question. Is there any way we can separate the posts results and the user results ?

    • See Sorting by post type on this page. With Relevanssi, “user” is a valid post type.

  • Muhammad Abid Saleem

    Hello Mikko,
    How are you ? Dear Mikko I have a question regarding Search.

    Question:- I have two type of user packages.

    1- Platinum package
    2- Basic package (Free)

    Currently I am using the Relevansi Premium. And its working fine and search the results that includes the users as well. My goal is to search users package wise first all sorted users list who have platinum/paid package after this all users list who have basic/Free package.
    Can I achieve my goal by using your plugin? If Yes, Then please tell me how I can
    do this.

    • Use relevanssi_hits_filter to reorganize the search results.

  • Muhammad Abid Saleem

    ok Thanks,

  • Muhammad Abid Saleem


    am using the Relevansi Premium its working fine. I have a question how I can modify
    search results template/listing style structure is there any setting available?

    • Relevanssi has nothing to do with the search results template style. That’s all up to your theme. Modify your theme search results template.

  • Muhammad Abid Saleem

    Ok thanks

  • Oludotun Olojede

    I am creating a new directory site that can display information like company name and pie chart based on user profile information as search result when visitors do a search on the website. Please can relevanssi help

    • Relevanssi provides search results. If you need search results, Relevanssi can help. How you visualize the results is up to you.

  • Jeff

    I am new to all of this. I want to make the search look through user names and other user profile fields. Here is my search template code, what do I need to change to make it search users?

    <?php printf( __( 'Search Results for: %s', 'twentytwelve' ), '’ . get_search_query() . ” ); ?>

  • Dr Sun

    “Relevanssi can search user profiles. So far the following data gets indexed from user profiles: first name, last name, display name and description. If you’re interested in having something else indexed, there’s an option in the options page.”

    where is this option, i cant see it on the options page

    • Are you using the free version of Relevanssi? Then that’s your problem. None of this applies to the free version, you need Relevanssi Premium to index and search user profiles.

  • Keith Pearson

    Okay, maybe I’m being an idiot but to enable the search results to display users profiles (in bbPress in my case), I have to change the setting in the admin to allow for profile searches, then edit some code?

    Sorry but it’s not clear from your post what file we need to edit and precisely what we need to add/edit in that file. And in the admin section where you have the ability to index profiles, it just says “Requires changes to search results template, see Relevanssi Knowledge Base”. So here I am again and I’m still none the wiser.

    And I should state that I’m using the Premium version.

    • Since you’re using Premium, please use the Premium support:

      Like the Relevanssi settings page says, you need to edit the search results template, which is usually search.php (not always, though, that’s why I can’t tell you exactly which file it is).

      Usually replacing “the_permalink();” on the search results template with “echo relevanssi_get_permalink();” is enough.

      • Keith Pearson

        Thanks Mikko – we can’t actually log-in to the site as the PW reminder isn’t sending-out an email and the form keeps saying our PW is incorrect.

        • Let’s get that fixed. I’ve sent you an email about it.

  • wojteksz

    hi, can Relevansi Premium search Custom Fields added to users table?

    • Relevanssi Premium can search user meta fields, yes.

  • sanjay kumar

    is it possible to search users with extended profiles such as company name, phone number, area of expertise created in gravity form with User Registration Add-on? I will buy the premium version if it can achieve this.

    • Given that I don’t know how the data in User Registration Add-on is stored, I can’t say for sure, but I’m fairly sure the answer is “yes”. Relevanssi has a filter hook you can use to add pretty much anything you want to user profiles before they are indexed, so if you can access the extended profile data from a PHP function, you can have Relevanssi index it.

  • Does is support buddypress

  • mundialisimo

    Hello. this plugin allows searching for users profile field and show, as a result a list of posts belonging to the users that fulfilled the searched criteria?

    • By default Relevanssi only shows the posts based on user name. However, Relevanssi has filters you can use to add any content you want to to the index, so you can make Relevanssi index exactly those user fields you need.