Yep, you can use the filter search_autocomplete_modify_results
.
Here’s some example code, which will add a particular post at the end of the results array:
add_filter('search_autocomplete_modify_results', 'add_search_result');
function add_search_result($results) {
$post_id = 123;
$title = get_the_title($post_id);
$url = get_post_permalink($post_id);
$results[] = array(
'title' => $title,
'url' => $url,
);
return $results;
}
Thanks! That was a very quick reply, and was easy to implement.
Is there a method for adding an element other than another link? I would like to add a button, or a div.
You can experiment with leaving the URL as just “#”, then using the “.ui-menu-item:last-child” selector in jQuery to apply styles and maybe override on-click behavior.
But no, you don’t get choice of HTML output.
Thank you sepehr125 for your help.