Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • nikkyandrei

    (@nikkyandrei)

    I try to find word “baby”, by all category and , by category . i see i works great. can u give me more details ? what word you use , for what category was the search , what products belong to other category
    You can write to me at nikkyandrei [at] gmail [dot] com

    nikkyandrei

    (@nikkyandrei)

    can you share a link ?

    nikkyandrei

    (@nikkyandrei)

    While looking for a solution to this problem, I read this post.
    Now I found the solution I will write it below.
    Also in my situation it war required to work on other language.

    <script>
      function avalcm_search_link(vas){
        var link1=document.getElementById("home_url").value;
        var sublink=document.getElementById("categ_base_lang").value;
        var link2="";
        if (vas!="") {
          var link2=sublink + "/" + vas + "/";
        }
        var link=link1+link2;
        document.getElementById('searchform_special').action = link;
      }
    </script>
    
    <form role="search" method="get" id="searchform_special" action="<?php echo esc_url( home_url( '/'  ) ); ?>">
      <div>
        <label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
        <input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" placeholder="<?php _e( 'Search for products', 'woocommerce' ); ?>" />
        <select onchange="avalcm_search_link(this.value)" >
           <option value=''>All</option>
       <?php
        $sql="SELECT taxonomy,slug, <code>name</code> from wp_term_taxonomy , wp_terms where wp_term_taxonomy.term_id=wp_terms.term_id and taxonomy in ('product_cat','') ORDER BY taxonomy ASC , term_taxonomy_id asc;";
        $allfilters = $wpdb->get_results($sql);
        foreach ($allfilters as $singlefilter) {
          echo '<option value="'. $singlefilter->slug.'">' . $singlefilter->name. '</option>';
        }
       ?>
       </select>
       <input type="submit" id="searchsubmit" value="<?php echo esc_attr__( 'Search' ); ?>" />
       <input type="hidden" name="post_type" value="product" />
       <input type="hidden" id="home_url" value="<?php echo esc_url( home_url( '/'  ) ); ?>" />
       <input type="hidden" id="categ_base_lang" value="<?php echo _x('product-category', 'slug', 'woocommerce') ?>" />
      </div>
    </form>

    So i change the action value of the form every time that i change value in select .

    I hope this will help someone

Viewing 3 replies - 1 through 3 (of 3 total)