Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Twitter Bootstrap have a javascript plugin called TypeAhead which is simular to Google Instant Search. I'm using it to pull the WordPress post titles into the search box, using the following code c/o @StephenHarris

data-source='[<?php 
    $posts = get_posts( array( 'numberposts' => -1, 'category' => 0 ) );
    $post_titles = wp_list_pluck( $posts, 'post_title' ); 
    $post_titles = array_map( 'esc_html', $post_titles ); 
    echo '"'.implode( '","', $post_titles ).'"';
?>]'

But how would you link the post permalink to the drop-down list of post titles?

share|improve this question
3  
I wouldn't use that, looks very inefficient. What happens when you get to ~1K posts? :) There are many autocomplete plugins out there which perform better –  onetrickpony Apr 4 '12 at 23:04
    
It's for a website that will only ever have a maximum of 100/150 posts. But I will look for some plugins options. –  TheLoneCuber Apr 5 '12 at 2:40
    
----deleted---- –  kaiser Apr 5 '12 at 4:21
    
There is actually an excellent Wordpress plugin that provides autocomplete that is much smarter than just searching the titles: Swiftype Search –  Joel Newcomer Mar 1 '13 at 13:02

1 Answer 1

up vote 0 down vote accepted

As @OneTrickPoney points out, there's an alternative in core.

jQuery UI autocomplete comes with WP default install.

Autocomplete, when added to an input field, enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering. By giving an Autocomplete field focus or entering something into it, the plugin starts searching for entries that match and displays a list of values to choose from. By entering more characters, the user can filter down the list to better matches.

This can be used to enter previous selected values, for example you could use Autocomplete for entering tags, to complete an address, you could enter a city name and get the zip code, or maybe enter email addresses from an address book.

You can pull data in from a local and/or a remote source: Local is good for small data sets (like an address book with 50 entries), remote is necessary for big data sets, like a database with hundreds or millions of entries to select from.

Autocomplete can be customized to work with various data sources, by just specifying the source option.

Explanation @jQuery

Just enqueue and go. Take a look at my Q, where you'll find some basics about it.

share|improve this answer
    
Thanks for the advise @kaiser. –  TheLoneCuber Apr 10 '12 at 7:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.