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.

71 comments User profile search

  1. 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?

    1. 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.

  2. Hi

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


    1. 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.

  3. 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.

    1. 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”.

  4. 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.

  5. Hello,

    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.

    1. 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.

        1. 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.

  6. 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?

  7. Hi,
    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 😉

    1. 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;

      1. 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?

        1. 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.

  8. 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.

      1. 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 ?

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

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

  10. 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.

  11. Hello,

    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?

  12. 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

  13. 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() . ” ); ?>

  14. “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

    1. 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.

  15. 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.

    1. 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.

      1. 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.

  16. 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.

    1. 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.

  17. 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?

    1. 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.

  18. How can I filter results to *only* include users, or, to exclude users?
    I have a series of checkboxes in my search form with name=”post_types[]” — this works for my other post types, but doesn’t seem to do the job for users. Thoughts?

    1. Setting “post_types” to “user” is the way to go, but it’s quite possible it doesn’t work quite right in the current version. This is something I’ve worked on recently, and something that will be fixed in the next version.

      Meanwhile you can use “relevanssi_hits_filter” to filter the results by post type.

  19. Hi,

    I have a lot of registered user profiles. Registration was done with Ultimate Member and there is a lot of data stored in the users meta. Also some data which should not be displayed.

    Is it possible to exclude some search results from the users meta?


      1. Relevanssi doesn’t index any user meta data by default, so you have to specify all meta data to index in any case. Just list the ones you want to index in the “Extra user fields to index:” setting.

  20. Hi Mikko,

    Great plugin!

    Everything is working great except for the Author search results where all title links are going to domain .com /2017/10/21 instead of the domain .com /author /name…

    All other searches are working well including the title link and the read more link.

    Thx in advance for your help!

    1. Sébastien, yes, it’s possible to search users by ACF fields, but you probably have to connect the fields to the user profiles manually. It’s a simple task, though, just requires adding one function to tell Relevanssi which fields you want to include.

        1. Have you listed the names of the fields in the “relevanssi_index_user_fields” option? If not, try that first. That option should contain a comma-separated list of user fields you want to include in the index.

          If that doesn’t help, you can use the “relevanssi_user_add_data” filter hook to add the field contents to the user object before it is indexed.

  21. um ok it CAN index user profiles, where is the check box for that? I am no PHP programmer and adding hooks is for hanging pictures on my walls.

    But seriously how to make this expensive plugin to search users? it doesnt out of the box?

  22. Hi,

    You say the plugin can index any field if you can access it from a php function. But you also say it does not support Buddypress. I have heavily customised Buddypress and added many fields/taxonomies and ACF fields etc to profiles. What are you meaning is ‘not supported’ if I can tweak to index any fields?

    Is it the destination link? Can I not just use a filter to redirect the results link to the Buddypress profile url instead of normal WP profile pages?

    1. I’m not even sure what the actual problem with BuddyPress is, I don’t know BuddyPress well enough. All I know is that Relevanssi has had lots of problems with it.

      You can definitely index any fields for a user profile, that’s not a problem. You can also use filters and your search results template to point the results to the profile. So if that’s all there is to BuddyPress, then sure, it should work out fine. I can’t really say anything else here than to try it out yourself, and that I can’t really support the combination, because I know nothing of BuddyPress.

    1. Steve, there’s no easy way to have Relevanssi sort the results by a user meta field, so the easiest solution is to create a relevanssi_hits_filter function that will sort the results by the last_name field.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.