Autocompleter

April 3rd, 2009

A Wordpress plugin for adding Autocomplete functionality to your blog search


Plugin download


Brief information
Adding autocomplete functionality to the blog search input field. The values provided are the tags and categories used in the blog.

Long description
This plugin adding autocomplete functionality to search input field. It is using core jQuery library as well as autocomplete jquery plugin from http://www.pengoworks.com/workshop/jquery/autocomplete.htm

This plugin requires zero configuration, but since version 1.2.0 there is admin screen where you can enable the extra ‘number of matches’ next to each option. You just need to activate and it’s ready to be used in the blog. The plugin is tested with Wordpress 2.6.5, but until there aren’t big core changes, it sould work for all future releases. I don’t have information if this plugin will work with older versions of Wordpress, but for sure it is working with 2.6.x. The last version 1.2.0 is tested on WP 2.7.1.

New in 1.2: This version could display number of matches found in the blog.
New in 1.2.1: Small fix for table prefixes and adding autosubmit once the item from the list is selected.

I would appreciate if you write an review/post in your blog with a link to my page: nik.chankov.net.

Thanks to



Installation
This section describes how to install the plugin and get it working.

  1. Download the plugin from Wordpress repository
  2. Upload `autocompleter` to the `/wp-content/plugins/` directory
  3. Activate the plugin through the ‘Plugins’ menu in WordPress
  4. {Optional} If you want to change the apperience of the dropdown, just play with autocompleter.css in the plugin folder.
  5. {Optional for 1.2.0} Go to Admin area under the Settings section. There is Autocompleter menu from which you can extend the plugin with ‘matched items’ option.



Frequently Asked Questions
Why this plugin is useful for users of your blog?
It’s useful because they can easily check what themes you writing for, and this way they could find the desired article more easily.

Is it possible to use it with non standard search like Google Custom Search Engine or similar?
Well, depends. Current version (1.1.2) reqires the name of the input field to be “s”, so if your search field has such name, there is no problem at all.

Is it heavy for my blog?
No, it selecting results from two joined tables, and it is not heavy at all.

Is it secure?
Actually it’s escaping the search string with functions provided from Wordpress, so it is secure as Wordpress.

Use contact page for support and other questions. Thanks!

Screenshots
Autocompleter.1.2 Autocompleter.1.1.2

  1. November 28th, 2008 at 23:14 | #1

    Too bad this handy plugin busts my preview feature on comments (while using Sexy Comments as plugin for that). So I deactivated this plugin.

    Running WP 2.7 beta 3 btw… :)

  2. Sumit Bhatia
    November 29th, 2008 at 16:52 | #2

    Thanks… Nice Plugin… :)

  3. December 16th, 2008 at 00:40 | #3

    For anyone that wants to autocomplete post titles instead of tags, I rewrote the sql query to compensate.

    Under values.php:

    Replace the select query with:
    “SELECT post_title FROM wp_posts WHERE post_title LIKE ‘$search%’ AND post_status LIKE ‘%publish%’”

    Replace: echo $word->name.”\n”;
    with
    echo $word->post_title. “\n”;

    Thanks for a great plugin. =) Happy searching!

    This pretty much just asks for post_title’s that are published so as not to spam the list with the revisions. After all we only need the title. This also removes the media files from the search box as well, because they are posted as inherit.

  4. December 16th, 2008 at 01:23 | #4

    Thanks for the update snetErz. Although I don’t think that the idea of search is to make autocomplete of the posts.

    The reason why I think this way is simple – autocompleter is just a guide (helper) which will help users to find relevant information. Tags and categories are exactly this.

    Anyway, your comment will be here, so anyone who want to use it with your approach is more welcome :)

    Cheers

  5. January 15th, 2009 at 18:10 | #5

    That’s a cool plug-in. It can help me big time with stuff in my blog. I should check it out tonight. Thanks for the awesome and useful plug-in. Cheers

  6. January 20th, 2009 at 20:07 | #6

    Kool stuff. I was looking for something similar. But this is just the ideal plug-in for my blog. Thanks for it. Also had a look around your blog. Really awesome posts. A definite bookmark. Great job.

  7. January 25th, 2009 at 09:05 | #7

    Great, I was looking for a similar plug-in. I’m doing this blog for my local sports club and needed something like this. Thanks for the plug-in. keep up the awesome work.

  8. January 28th, 2009 at 09:51 | #8

    A friend of mine had visited your page few days back and gave me this plug-in for my use. I have to hand it to you it worked just perfect. Just dropped by to thank you for the awesome plug-in.

  9. February 2nd, 2009 at 14:55 | #9

    I really like the sound of zero configuration, I have not been happy with the standard wordpress search interface and have been looking for a improvement. Most novices who wish to learn will really benefit from the extra prompting when searching for their requirements. Going to install it now!

  10. February 3rd, 2009 at 21:00 | #10

    Interesting plug-in. The idea is great. Would definitely work well. And no configuration is really awesome. Need to try this out tonight thanks for the awesome plug-in. Cheers

  11. February 4th, 2009 at 20:40 | #11

    If you reference the search box using jQuery(”input[name='s']“), people wont need to add the id to their templates.

  12. February 4th, 2009 at 22:24 | #12

    Dave, great hint! I will add definitely in the plug-in. I’ve always rely on id’s but never on name attribute, but you are completely right!

    Thank again

  13. February 9th, 2009 at 11:17 | #13

    Great work Nik. The plug-in is a really good idea. Never came across anything like it. and it is really useful. Nice tip Dave, I went through the code but i didn’t notice it until I saw your comment. Great job Nik and Dave. Appreciate the efforts. Cheers

  14. February 9th, 2009 at 12:05 | #14

    Well, this is already implemented in the plug-in :)

  15. February 11th, 2009 at 20:09 | #15

    Hey, Brilliant plug-in. Really lucky that I came across this article, was for a plug-in that could do this. Thanks.

  16. February 14th, 2009 at 15:44 | #16

    Referencing the search box using jQuery(”input[name='s']“) may be fine for a lot of people, however I liked the old way of using id=”s” better and here is why.

    I have a big old search box in my template in the header section (see http://www.mehmet.com/).

    I modified the plugin css to make the drop down search results box look best (width-wise) with that main search box. The modification involved several tweaks one of which was to give the drop-down a 43 pixel pad on the right side.

    When my visitors reach a 404 page, which includes the theme search form my site displays two search boxes, one in the header and one in the page body — as in http://www.mehmet.com/some-nonexistent-page.

    Because of the 43 pixel right pad, the width of the drop down for the search box in the page body is too wide…

    By not using the id=”s” I was able to exclude the search box in the page body but now I can’t.

    Is there a way to exclude a search field from using the autocompleter?

  17. February 15th, 2009 at 09:31 | #17

    Nice work Nik. Love the plug-in. Worked really well for me too. No hiccups at all. Awesome job. Keep it up.

  18. February 18th, 2009 at 22:15 | #18

    @Mehmet why dont you remove the second search form? :) easy as that.

    Another option which is coming to my mind is:
    1. rename the search field for example “s1″ or “search”
    2. put a hidden field named “s” and on submit make

    $('#s').attr('value', $('#s1').attr('value'));

    third option is to modify the plugin it is one file :) just change it and forget it :)

    Hope this will help

  19. February 22nd, 2009 at 06:28 | #19

    A really useful plug-in Nik. Appreciate all the effort put into it. Might just try it out hen i get the time. Keep it up. Cheers

  20. Nathan
    February 25th, 2009 at 12:17 | #20

    A great plugin! But for some reason it doesn’t line up under the search box and sits vertically halfway across the input box. The padding in the css seems to only move the results over, not the box. Anyway I can fix this?

  21. February 27th, 2009 at 00:05 | #21

    Nice work Nik:P A great plugin!! :)

  22. March 3rd, 2009 at 06:01 | #22

    Cool plug-in Nik. good job with it :) Certainly worth a try. The description sounds really good. Thanks and good job

  23. April 1st, 2009 at 06:42 | #23

    Hey Nik. That’s a really cool plug-in. Definitely will try it out and see tonight. Keep up the good work. Cheers

  24. April 3rd, 2009 at 14:31 | #24

    Works great, thank you

  25. Travis
    April 9th, 2009 at 22:01 | #25

    You’ve done an incredible job with this plugin, Nik.

    One thing I was wondering, if you’ve considered enabling it to suggest terms for multiple words? Works like a charm for the first couple characters you type, but if you add a space and another word, it doesn’t suggest anything else.

    Would you consider such a feature?

  26. April 9th, 2009 at 22:21 | #26

    Travis, basically you suggesting an Facebook style autosuggest and add, right? If so, it’s not a bad idea… probably I will realize it in the future

  27. Travis
    April 9th, 2009 at 22:34 | #27

    Something like Facebook (and this example http://devthought.com/blog/projects-news/2008/01/textboxlist-meets-autocompletion/) might be alright.

    But I was just thinking something as simple as this:

    Type and match your first query, then add spaces and multiple words.

  28. Travis
    April 9th, 2009 at 22:35 | #28

    Here’s the image I tried to enclose:

    http://img9.imageshack.us/img9/6618/suggestwordpress.jpg

  29. Steven
    April 13th, 2009 at 00:39 | #29

    Hmm… I might be a bit blind…. but I can’t find a demo of this plugin.
    Is there one?

  30. April 13th, 2009 at 09:24 | #30

    Steven, the demo is in the top-right corner of this blog – where the search field of this blog is located :) Try to search for “Wordpress” and you will see the demo. :)

  31. Øyvind Svedman
    April 18th, 2009 at 22:46 | #31

    Hey, great plugin!

    However, it breaks XHTML 1.0 Strict validation because you didn’t comment out the JavaScript code inside the SCRIPT tag in autocompleter.php lines 55-80. I have added this to my local copy and it now validates. :)

    BTW, how can I make the autocompletion drop-down open upwards instead of downwards?

  32. April 19th, 2009 at 08:28 | #32

    Awesome plug in. Have used for a few days now and totally enjoying it. Thanks a lot man.

  33. April 26th, 2009 at 12:30 | #33

    I made a test on this website and noticed that the number of matches is always less than the real number of posts after submitting the search. Should it be?

  34. Travis
    May 6th, 2009 at 21:25 | #34

    Hey Nik,
    Quick question for you…how would you go about connecting to another WP database?

    As an example, I have one main site, and several sub-domains, each with their own WP install. I’d love to tap the search autocompleter on the main site, into one of the sub-domain’s databases.

    Is there an easy way to add the db path and login info to your plugin, or use the wp-config.php of the sub-domain’s install?

  35. May 6th, 2009 at 23:02 | #35

    Travis,

    autocompleter is working as wp blog – so only one database. If you want to attach other databases, the easiest way is to edit the values.php and to create extended sql which will collect all tags from all databases.

  36. Øyvind Svedman
    May 6th, 2009 at 23:04 | #36

    Is there any way to make the drop-down open upwards?

  37. Travis
    May 6th, 2009 at 23:11 | #37

    @Nik Chankov

    Thanks, Nik. I’ll give that a shot.

  38. May 6th, 2009 at 23:14 | #38

    Don’t know, check the autocomplete jQuery plugin which I’ve used, but I’ve doubt it’s native. :(

  39. May 7th, 2009 at 12:06 | #39

    Hey Nik,

    I like this plugin. It works great. I love the zero config aspect of it. I installed it a couple days ago and I am loving it. I also appreciate the help towards getting it figured out.

    Thanks again

  1. November 30th, 2008 at 12:39 | #1
  2. December 13th, 2008 at 16:32 | #2
  3. December 14th, 2008 at 00:33 | #3
  4. April 3rd, 2009 at 12:56 | #4
  5. April 5th, 2009 at 17:56 | #5
  6. April 14th, 2009 at 11:06 | #6
  7. April 17th, 2009 at 06:46 | #7
  8. April 19th, 2009 at 23:27 | #8
  9. April 21st, 2009 at 23:49 | #9
  10. May 11th, 2009 at 14:42 | #10

*
To prove that you're not a bot, enter this code
Anti-Spam Image