Ajax Search Form

jQuery(document).ready(function() {jQuery
jQuery(‘#schoolword’).on(‘input’, function() {
var searchKeyword = jQuery(this).val();
var searchType = jQuery(‘#searchby’).val();
if (searchKeyword.length >= 3) {
jQuery.post(‘/includes/schoolsearch-ajax.php’, { keywords: searchKeyword,searchtype: searchType }, function(data) {
jQuery(‘ul#schoollist’).empty()
jQuery.each(data, function() {jQuery(‘ul#schoollist’).append(‘<li>//<a href=”//’+this.link+'”>’ + this.t//itle + ‘</a></li//>’);

 

‘);
});
}, ‘json’);
}
});
});

Search Form

” value=”” name=”s” />

    ajax-search.php

    <?php
    require_once(‘../../../wp-load.php’);
    global $wpdb;
    if ( !function_exists( ‘is_woocommerce_active’ ) ) require_once ‘../../plugins/woocommerce/woocommerce.php’;
    $arr = array();

    if (!empty($_POST[‘keywords’])) {
    $keywords = $_POST[‘keywords’];
    $searchtype = $_POST[‘searchtype’];
    if($searchtype == ‘product’){
    $sql = “SELECT ID, post_title FROM wp_posts WHERE post_title LIKE ‘%”.$keywords.”%’ LIMIT 10″;
    $posts = $wpdb->get_results($sql);
    if(count($posts)>0){
    foreach ($posts as $post)
    {
    $link= get_permalink($post->ID);
    $arr[] = array(‘link’ => $link, ‘title’ => $post->post_title);
    }
    }
    }
    else{
    $sql1 = “SELECT slug, name FROM wp_terms WHERE name LIKE ‘%”.$keywords.”%’ LIMIT 10″;
    $categories = $wpdb->get_results($sql1);
    if(count($categories)>0){
    foreach ($categories as $woo_cat)
    {
    $link= get_term_link( $woo_cat->slug, ‘product_cat’ );
    $arr[] = array(‘link’ => $link, ‘title’ => $woo_cat->name);
    }
    }
    }
    if(count($arr)==0){
    $arr[] = array(‘link’ => ‘#’, ‘title’ => ‘Nothing Found’);
    }
    }
    echo json_encode($arr);
    ?>

    Advertisements

    Woocommerce Category Image show

    add_action( ‘woocommerce_archive_description’, ‘woocommerce_category_image’, 2 );
    function woocommerce_category_image() {
    if ( is_product_category() ){
    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, ‘thumbnail_id’, true );
    $image = wp_get_attachment_url( $thumbnail_id );
    if ( $image ) {
    echo ‘//

    //

    //

    //</div>’;
    }
    }
    }

    function category_has_children() {

    if ( is_product_category() ){
    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $children = get_categories( array( ‘child_of’ => $cat->term_id, ‘taxonomy’ => ‘product_cat’ ) );
    return ( $children );
    }

    }