A
A
Alexander Pyatkov2016-10-12 12:41:54
WordPress
Alexander Pyatkov, 2016-10-12 12:41:54

What did I do wrong in Wordpress search terms?

Hello.
Tell me please. The bottom line is this: I want to make a selection of tires on the site, I work on Woocommerce, I made a filter. 597d29780408405fad6c655410981c17.JPG
Tell me how to make it work...
Here is the code.

<table width="50%" align="center" class="styled-select2">
      
    <tbody><tr><td><div align="center"><h5>Ширина</h5></div>
      <p>
        <select name="shirina_category">
                                <option value="0">-</option>
        <option value="125">125</option>
        <option value="135">135</option>
        <option value="145">145</option>
        <option value="155">155</option>
        <option value="165">165</option>
        <option value="175">175</option>
        <option value="185">185</option>
        <option value="195">195</option>
        <option value="205">205</option>
        <option value="215">215</option>
        <option value="225">225</option>
        <option value="235">235</option>
        <option value="245">245</option>
        <option value="255">255</option>
        <option value="265">265</option>
        <option value="275">275</option>
        <option value="285">285</option>
        <option value="295">295</option>
        <option value="305">305</option>
        <option value="315">315</option>
        <option value="325">325</option>
        <option value="335">335</option>
        <option value="345">345</option>
        <option value="355">355</option>
        <option value="365">365</option>
        <option value="375">375</option>
        <option value="385">385</option>
        <option value="390">390</option>
        <option value="395">395</option>
        <option value="400">400</option>
        <option value="425">425</option>
        <option value="500">500</option>
        <option value="530">530</option>
        <option value="6">6</option>
        <option value="6.5">6.5</option>
        <option value="7">7</option>
        <option value="7.5">7.5</option>
        <option value="8.15">8.15</option>
        <option value="8,25">8.25</option>
        <option value="9">9</option>
        <option value="9.5">9.5</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="11.2">11.2</option>
        <option value="12">12</option>
        <option value="13.6">13.6</option>
        <option value="14">14</option>
        <option value="14.9">14.9</option>
        <option value="15.5">15.5</option>
        <option value="16">16</option>
        <option value="16.5">16.5</option>
        <option value="16.9">16.9</option>
        <option value="17.5">17.5</option>
        <option value="18">18</option>
        <option value="18.4">18.4</option>
        <option value="20">20</option>
        <option value="20.5">20.5</option>
        <option value="21.3">21.3</option>
        <option value="30">30</option>
        <option value="31">31</option>
        <option value="32">32</option>
        <option value="33">33</option>
        <option value="35">35</option>
        <option value="37">37</option>
        <option value="38">38</option>
              </select>
        </p></td>
  
    
    <td><div align="center"><h5>Высота</h5></div>
      <p>
        <select name="product_size2">
        <option value="0">-</option>
        <option value="7">7</option>
        <option value="9">9</option>
        <option value="9.5">9.5</option>
        <option value="10">10</option>
        <option value="10.5">10.5</option>
        <option value="11">11</option>
        <option value="11.5">11.5</option>
        <option value="12">12</option>
        <option value="12.5">12.5</option>
        <option value="13">13</option>
        <option value="13.5">13.5</option>
        <option value="14">14</option>
        <option value="14.5">14.5</option>
        <option value="20">20</option>
        <option value="25">25</option>
        <option value="30">30</option>
        <option value="35">35</option>
        <option value="40">40</option>
        <option value="45">45</option>
        <option value="50">50</option>
        <option value="55">55</option>
        <option value="60">60</option>
        <option value="65">65</option>
        <option value="70">70</option>
        <option value="75">75</option>
        <option value="80">80</option>
        <option value="85">85</option>
        <option value="90">90</option>
        <option value="95">95</option>
        <option value="105">105</option>
              </select>
        </p></td>
  
    
    <td><div align="center"><h5>Диаметр</h5></div>
      <p>
      <select name="product_size3" >
                		<option value="0">-</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">10</option>
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18">18</option>
        <option value="19">19</option>
        <option value="20">20</option>
        <option value="21">21</option>
        <option value="22">22</option>
        <option value="24">24</option>
              </select>
        </p></td>
        
    <form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <td><div align="center"><h5>Сезонность</h5></div>
      <p>
    <select name="product_cat">
                <?php wp_list_categories( 'title_li=&taxonomy=product_cat&show_count=1' ); ?>
    <option value="0"><?php esc_attr_e( '-', 'maxstore' ); ?></option>
    <?php
                 $categories = get_categories( 'taxonomy=product_cat' );
                 foreach ( $categories as $category ) {
                 $option = '<option value="' . esc_attr( $category->category_nicename ) . '">';
                 $option .= esc_html( $category->cat_name );
                 $option .= ' (' . absint( $category->category_count ) . ')';
                 $option .= '</option>';
                 echo $option;
                  }
                    ?>
      </select>
        </p></td>
  </tr>
  <tr>
      <td colspan="4"><input type="submit" value="Подобрать" class="submit">
          

          </td>
      
            </tr>
    </tbody></table>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2016-10-20
@Palych_tw

"What did I do wrong on the search" - you did nothing at all. Why are your width, height and diameter out of shape? How do you want to get their values ​​on form submission? Why are they statically inferred and not chosen from existing attribute values? Where do you have $_GET processing? You need to put all the selects in the form, action in the form to the current address, in functions.php write a hook in pre_get_posts, where the data from $_GET would be collected and a meta_query request would be built with the OR or AND relation you need. I would try like this. But I do not recommend reinventing the wheel. There are several ready-made plugins. For example https://wordpress.org/plugins/woocommerce-ajax-filters/

A
Alexander Pyatkov, 2016-10-20
@fantomcik

did so... but the query looks like this: ./?filter1=205&filter2=50&height=R17&filter
and you need this type /?s=215%2F55+R17&post_type=product tell me how to fix it...

<script type="text/javascript">
  // Описываем функцию, которая будет выполняться
  // при отправке формы:
  // form - ссылка на форму
  // filters - хеш фильтров и параметров
  function addFilters(form, filters) {

    // Получаем элемент нашего "фильтра"
    var filter_query = document.getElementsByName("filter")[0];
    
    // Очищаем:
    filter_query.value = "";
    
    // "Аналог" foreach из php:
    for (var i in filters) if (filters.hasOwnProperty(i)) {
      // Получаем фильтр по имени (первый элемент с таким именем):
      var filter = document.getElementsByName(i)[0];
      // Лучше делать проверку, что выбран не первый вариант:
      if (filter.selectedIndex > 0) {
        // Теперь добавляем нужный нам "параметр":
        filter_query.value += filters[i];
      }
    }
  }
</script>

<form method="get" onsubmit="addFilters (this, {'filter1''/','filter2','filter3'})" action="./?s=&post_type=product">
            <SELECT name="filter1" style="margin-top: 5px;">
              <option value="">Ширина </option>
                                      <option value="6.15">6.15</option>
                                        <option value="6.45">6.45</option>
                                        <option value="6.95">6.95</option>
                                        <option value="7">7</option>
                                        <option value="7.5">7.5</option>
                                        <option value="9">9</option>
                                        <option value="10">10</option>
                                        <option value="12">12</option>
                                        <option value="30">30</option>
                                        <option value="31">31</option>
                                        <option value="33">33</option>
                                        <option value="135">135</option>
                                        <option value="155">155</option>
                                        <option value="165">165</option>
                                        <option value="175">175</option>
                                        <option value="185">185</option>
                                        <option value="195">195</option>
                                        <option value="205">205</option>
                                        <option value="215">215</option>
                                        <option value="225">225</option>
                                        <option value="235">235</option>
                                        <option value="245">245</option>
                                        <option value="255">255</option>
                                        <option value="265">265</option>
                                        <option value="275">275</option>
                                        <option value="285">285</option>
                                        <option value="295">295</option>
                                        <option value="315">315</option>
                                        <option value="385">385</option>
            </SELECT>
      
            <SELECT name="filter2" style="margin-top: 5px;">
                                <option value="">Высота</option>
                                      <option value="9.5">9.5</option>
                                        <option value="10.5">10.5</option>
                                        <option value="12.5">12.5</option>
                                        <option value="35">35</option>
                                        <option value="40">40</option>
                                        <option value="45">45</option>
                                        <option value="50">50</option>
                                        <option value="55">55</option>
                                        <option value="60">60</option>
                                        <option value="65">65</option>
                                        <option value="70">70</option>
                                        <option value="75">75</option>
                                        <option value="80">80</option>
                                        <option value="85">85</option>
                                        <option value="90">90</option>
                                 </SELECT>

                        <select class="filter3" name="height">
                                    <option value="">Диаметр </option>
                                      <option value="12">12</option>
                                        <option value="12C">12C</option>
                                        <option value="13">13</option>
                                        <option value="13C">13C</option>
                                        <option value="14">14</option>
                                        <option value="14C">14C</option>
                                        <option value="15">15</option>
                                        <option value="15C">15C</option>
                                        <option value="16">16</option>
                                        <option value="16C">16C</option>
                                        <option value="R17">17</option>
                                        <option value="17.5">17.5</option>
                                        <option value="18">18</option>
                                        <option value="19">19</option>
                                        <option value="19.5">19.5</option>
                                        <option value="20">20</option>
                                        <option value="21">21</option>
                                        <option value="22">22</option>
                                        <option value="22.5">22.5</option>
                                    </select>
                           <input type="hidden" name="filter" value="" />
                       <input type="submit" value="Искать">
                      </form>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question