I have some code in my functions.php that creates a list of auto-suggested items based on a form's text:
<?
add_action('wp_enqueue_scripts', 'se_wp_enqueue_scripts');
function se_wp_enqueue_scripts() {
wp_enqueue_script('suggest');
}
add_action('wp_head', 'se_wp_head');
function se_wp_head() {
?>
<script type="text/javascript">
var se_ajax_url = '<?php echo admin_url('admin-ajax.php'); ?>';
jQuery(document).ready(function() {
jQuery('#love-input').suggest(se_ajax_url + '?action=se_lookup', {
onSelect: function() {
thevalue = this.value;
thevalue = thevalue.split(' (');
jQuery('#love-input').val(thevalue[0]);
}
});
});
</script>
<?php
}
add_action('wp_ajax_se_lookup', 'se_lookup');
add_action('wp_ajax_nopriv_se_lookup', 'se_lookup');
function se_lookup() {
global $wpdb, $wp_query;
$search = like_escape($_REQUEST['q']);
$query = 'SELECT ID,post_title FROM ' . $wpdb->posts . '
WHERE post_title LIKE \'%' . $search . '%\'
AND post_type = \'loves\'
AND post_status = \'publish\'
ORDER BY post_title ASC';
foreach ($wpdb->get_results($query) as $row) {
$post_title = $row->post_title;
$id = $row->ID;
$post_count = $wpdb->get_var("
SELECT COUNT(*) FROM $wpdb->postmeta
WHERE post_id = $id
");
echo $post_title . ' (' . $post_count . ')' . "\n";
}
die();
}
?>
I'm trying to place this box under the text field, but the output it always a with a class "ac_results" that appears at the very bottom of the html. Problem is I don't know where this and class are coming from?? It's not in admin-ajax.php, and I'm not calling any other files.. or does wordpress do this automatically?
How Can I tell it exactly where to appear in my html?