Viewing 5 replies - 1 through 5 (of 5 total)
  • 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;
    }
    Thread Starter statstutor

    (@statstutor)

    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.

    Thread Starter statstutor

    (@statstutor)

    Thank you sepehr125 for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to append item to the results list’ is closed to new replies.