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

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Flickr recent photos

rss
iPad as teleprompter.Need the install CD for Internet Explorer 4? I *HAD* one.Zippy from the olden days.Ants on a log for supperCity of SpokaneAnother day ends

User login

Connect
Sign in using Facebook