How to display the category dropdown auto search list when key press?


I have a search field. There is no issue with the search if I enter anything on this and click on button then it’s redirecting on the page where I can get my search result.

What I am doing is, I have to display the category dropdown auto search list when the user enters any text in the search field. I found one plugin ( also demo here ( I am trying to do the same but I can’t use the plugin.

I need to know what query I have to use on the ajax to get the output?

Form code

function search_form($atts) { 
     $form = '<section class="universalSearch"><div class="search search-form"><form role="search" method="get" action="' . home_url( '/' ) . '" >
    <label class="screen-reader-text" for="s">SEARCH</label>
     <input type="search" class="search-field universalSearchField" value="' . get_search_query() . '" name="s"  placeholder="Search" />
     <input type="submit" id="searchsubmit" class="search-submit" value="'. esc_attr__('Go', 'domain') .'" />
     <script src=""></script>
          (function($) {  // ready handler
$(".universalSearchField").keypress(function() {
      $.post("/wp-admin/admin-ajax.php", {"action":"universalSearchlist"}, function(response) {
        console.log( response );
     return $form;

add_shortcode( 'get_search_form', 'search_form');

AjAX code

function universalSearch(){
    $args = array(
     's' => $_REQUEST[ 'universalSearchlist' ],
     'cat' => 'category'
    $the_query = new WP_Query( $args );
    foreach ($the_query->posts as $post) {

    return $data;
, Naren Verma 3 years 2020-08-24T05:10:18-05:00 0 Answers 44 views 0

Leave an answer