我正在使用wordpress的内置建议脚本创建基于自定义帖子标题的自动建议表单。。。
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() {
?>
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();
}
目前,它在建议表单中标题旁边的括号中显示与每篇文章相关的元数据。
问题是,当单击建议的项目时,它会将括号以及标题添加到表单中。
我希望括号在建议标题时可见,但在单击建议标题时不显示在表单框中。