• Resolved AnotherChance

    (@anotherchance)


    This is my searchform.php:

    <form name="pjsearch" id="pjsearch" method="POST" action="<?php bloginfo('url');?>/search-results/">
    	<div id="pjcatform"><input type="text" id="pjcat" name="pjcat" placeholder="What service are you looking for?" /></div>
    	<div id="pjtagform"><input type="text" id="pjtag" name="pjtag" placeholder="Which area are you in?" /></div>
    	<input type="submit" id="pjsearchsubmit" name="pjsearchsubmit" value="Search" /></div>
    </form>

    my .js file:

    $(document).ready(function(){
    	$('#pjcat').suggest(myAjax.ajaxurl + '?action=search_cat', {minchars:1});
        });
    
    $(document).ready(function(){
    	$('#pjtag').suggest(myAjax.ajaxurl + '?action=search_tag', {minchars:1});
        });

    functions.php:

    function search_cat() {
        global $wpdb;
    
        $search = esc_sql( $wpdb -> esc_like($_REQUEST['q']));
    
    	$query = 'SELECT term_id,name FROM ' . $wpdb->terms . '
            WHERE name LIKE \'' . $search . '%\'
            ORDER BY name ASC';
    
        foreach ($wpdb->get_results($query) as $row) {
            $name = $row->name;
            $id = $row->term_id;
    
            echo $name . "\n";
        }
        exit();
    }
    
    add_action('wp_ajax_search_cat', 'search_cat');
    add_action('wp_ajax_nopriv_search_cat', 'search_cat');
    
     function search_tag() {
        global $wpdb;
    
        $search = esc_sql( $wpdb -> esc_like($_REQUEST['q']));
    
    	$query = 'SELECT term_id,name FROM ' . $wpdb->terms . '
            WHERE name LIKE \'' . $search . '%\'
            ORDER BY name ASC';
            $rows = $wpdb->get_results($query);
        foreach ($rows as $row) {
            $name = $row->name;
            $id = $row->term_id;
    
            echo $name, "\n";
        }
        exit();
    }
    
    add_action('wp_ajax_search_tag', 'search_tag');
    add_action('wp_ajax_nopriv_search_tag', 'search_tag');

    I can see the suggest does work as I see the response in dev tools in Chrome. The problem is the response is not echoing on the web page. Any Suggestions?

Viewing 1 replies (of 1 total)
  • Thread Starter AnotherChance

    (@anotherchance)

    Right, I have managed to sort this out. The suggest was working all the time. It was displaying as a list below my footer and because my background colour was black I couldn’t see it. Now I need to find out how to style it.

Viewing 1 replies (of 1 total)

The topic ‘Suggest Response’ is closed to new replies.