I'm using wordpress' built in suggest scripts to create an auto-suggest form based on custom post titles...

add_action('wp_enqueue_scripts', 'se_wp_enqueue_scripts');
function se_wp_enqueue_scripts() {

add_action('wp_head', 'se_wp_head'); function se_wp_head() { ?>

var se_ajax_url = ''; jQuery(document).ready(function() { jQuery('#stuff-input').suggest(se_ajax_url + '?action=se_lookup'); });

add_action('wp_ajax_se_lookup', 'se_lookup'); add_action('wp_ajax_nopriv_se_lookup', 'se_lookup');

function se_lookup() { global $wpdb;

$search = like_escape($_REQUEST['q']); $query = 'SELECT ID,post_title FROM ' . $wpdb->posts . ' WHERE post_title LIKE \'' . $search . '%\' AND post_type = \'stuff\' AND post_status = \'publish\' ORDER BY post_title ASC'; foreach ($wpdb->get_results($query) as $row) { $post_title = $row->post_title; $id = $row->ID; $meta = get_post_meta($id, 'location', TRUE); echo $post_title . ' (' . $meta . ')' . "\n"; } die(); }

Currently, it displays meta-data associated with each post in parentheses next to the title in the suggest form.

The problem is when the suggested item is clicked, it adds the parentheses to the form, as well as the title.

I want the parentheses to be visible when the title is SUGGESTED, but not to appear in the form box when the suggested title is clicked.

1 Answer 1


Change the jQuery:

jQuery('#stuff-input').suggest(se_ajax_url + '?action=se_lookup', {
    onSelect: function() {
        thevalue = this.value;
        thevalue = thevalue.split(' (');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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