Searching your Drupal site for Content by Author

April 19, 2010, 13:22 pm

Recently at work the issue came up that people were searching our site for all the posts by an author but it only returning the author's biography node. After some digging, I finally found a simple solution thanks to Julia at juliakm.com.

The solution was simple and worked exactly as I was hoping it would. All you have to do is add the following code to your custom module (You don't have a custom site module?).

 

//Adding author name to the search index
function custom_helper_nodeapi($node, $op, $arg = 0) {
   switch ($op) {
     case 'update index':
       if ($node->uid) {
          $user = user_load(array('uid' => $node->uid));
          return $user->name;
       }
    }

  }

Hopefully you find this helpful. The only drawback to this method is that you will have to trigger a reindex of all the content on the site.

Post new comment

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

More information about formatting options

Flickr recent photos

rss
The BEST Indian Restaurant in North America... Dangerous AND unlawful!Good morning Jesus!Iced overGlass WorkPure Maple

User login

FriendFeed

 RT @dailybible: Don't fear, I am w/you; don't be dismayed, I am your God. I will strengthen & help you; I will uphold you. Is 41:10 http://t.co/7jcVYN4t
From Twitter, posted Sunday, February 5, 2012 - 07:26.
 The BEST Indian Restaurant in North America @ Woodlands Indian Cuisine http://t.co/O6U7famE
From Twitter, posted Saturday, February 4, 2012 - 18:13.
 The BEST Indian Restaurant in North America
From Flickr, posted Saturday, February 4, 2012 - 18:13.
 ... Dangerous AND unlawful! http://t.co/DKxYbK1E
From Twitter, posted Saturday, February 4, 2012 - 08:53.
 Good morning Jesus!
From Flickr, posted Saturday, February 4, 2012 - 08:27.
 Good morning Jesus! http://t.co/NRypdopt
From Twitter, posted Saturday, February 4, 2012 - 08:27.