How can I render/display user profile or registration field on search result page (user search)?

enter image description here


Copy the template file YOUR_SITE/modules/search/search-result.tpl.php to your theme and modify the code inside with this:

//obtaining the username
$username = explode('(', $title);
$username = trim($username[0]);
//getting the user object
$user = user_load_by_name($username);
<li class="<?php print $classes; ?>"<?php print $attributes; ?>>
  <?php print render($title_prefix); ?>
  <h3 class="title"<?php print $title_attributes; ?>>
    <a href="<?php print $url; ?>"><?php print $title; ?></a>
   * The following lines will print the info
  print $user->field_date_of_birth[LANGUAGE_NONE][0]['value'] . "<br>";
  print $user->field_gender[LANGUAGE_NONE][0]['value'] . "<br>";
  print $user->field_your_industry[LANGUAGE_NONE][0]['value'] . "<br>";
  print $user->field_your_city[LANGUAGE_NONE][0]['value'] . "<br>";
  print $user->field_zip_code[LANGUAGE_NONE][0]['value'] . "<br>";
  print $user->field_countrynew[LANGUAGE_NONE][0]['value'] . "<br>";
  <?php print render($title_suffix); ?>
  <div class="search-snippet-info">
    <?php if ($snippet): ?>
      <p class="search-snippet"<?php print $content_attributes; ?>><?php print $snippet; ?></p>
    <?php endif; ?>
    <?php if ($info): ?>
      <p class="search-info"><?php print $info; ?></p>
    <?php endif; ?>

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.