WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

Change the jQuery:

jQuery('#stuff-input').suggest(se_ajax_url + '?action=se_lookup', {
    onSelect: function() {
        thevalue = this.value;
        thevalue = thevalue.split(' (');
share|improve this answer
beautiful! Thanks – marctain Jul 15 '12 at 23:35

Your Answer


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.