I am currently trying to create a wordpress search function that shows live results underneath the search bar. There is an example on the World Bank website (screens below). I’m not looking for an autofill like you would find on Google.com which completes words you type, rather I want it to find actual posts on the site.
I tried doing a scrub through WordPress Answers and other similar resources but have only run into implementing a Google type search which is not what I am looking for. Any help or points in the right direction would be greatly appreciated.
The following uses jQuery UI Autocomplete, which has been included in WordPress since 3.3. (I’ve borrowed the format from @Rarst :D).
It’s still not precisely what you’re after, but gives you a good starting point. The following uses a the basic jQuery UI styling, but you can use the one that’s currently worked out on trac and call that from your plug-in folder.
Ok, this would be very basic example code that uses native
suggest.js
, WP core for Ajax and binds to default search form (from unmodifiedget_search_form()
call). It’s not precisely what you asked for, but incremental search is huge pain to get perfect. 🙂You must do it using Ajax of course, but here there is a problem. Since WordPress uses MySQL, you might over stress your server with searching if you try to fill the search with the real Database queries trough Ajax, but what you might do is develop a system where all the posts are saved in to one big “wp_options” field and then when a search is done you query from that instead of doing a real search. But remember you need to update this chunk of text/serialized variable every time you create or edit a post.
If you are not willing to spend some time to develop this solution, I wouldn’t recommend you doing this sort of “live search”.