You are here:  » Search based on three dropdown fields


Search based on three dropdown fields

Submitted by koen on Sun, 2016-02-07 12:32 in

Hi David,

I'm investigating the opportunity to make a comparison site for snow chains. Since the right snow chain depends on wheel-size etc., I'm wondering if the following is possible...
I'm a great fan of comparisson by EAN code, so I created the EAN field and implemented the EAN mapping.

For now, I would like to implement two more things to enable searching based on wheel-size etc.
1. For each EAN fill the database with a field that stores Tyre width, Cross-section ratio, Radial, using the Scan Set filter. Each EAN can have multiple sizes, so I'm thinking about storing them using semicolons to seperate the size. For example you get:
Productname: Blabla 9 77
Brand: Blabla
EAN: 9006350247985
Sizes: 225/80-14;265/60-14;215/80-15;225/75-15;255/60-15;275/50-15;195/85-16;205/80-16;215/70-16;215/75-16;235/60-16;245/55-16;255/50-16;225/60-17;235/55-17;245/50-17;205/70-17.5;225/50-18;225/55-18;235/50-18;245/45-18;255/45-18;235/40-19;245/40-19;225/40-20;
--> I can manage to get this done.
2. This is were I need your help; I would like to make a search engine on my front page with three dropdowns:
a. Tyre width (eg 225)
b. Cross-section ratio (eg 55)
c. Radial (eg 18)
And then hit the search button, were the search looks into the product's sizes field and find the right combination. (eg in this case the product as described above).
I would like to combine this kind of searching with the old-fashioned way of searching, so keeping the searchbox (combind with autofill) to search on productname in tact.

Do you have experience in making this kind of searches?

Cheers,
Koen

Submitted by support on Mon, 2016-02-08 09:35

Hello Koen,

It would be straight forward to present separate drop down boxes for an exact specification which are then converted in pto_search.php into a new size: search operator, which will then propagate nicely throughout pagination, changing of sort order and filtering etc.

To do this, simply add the drop-down boxes to your Main / Search Form template (wp-admin > Settings > PriceTapestry.org) using the names pto_width, pto_ratio and pto_radial for example:

Width:
<select name="pto_width">
  <option value="">Width...</option>
  <option value="195">195</option><option value="200">200</option>
</select>
<select name="pto_ratio">
  <option value="">Ratio...</option>
  <option value="50">50</option><option value="75">75</option>
</select>
<select name="pto_radial">
  <option value="">Radial...</option>
  <option value="15">15</option><option value="17">17</option>
</select>

(options will need filling out of as required of course)

And then in pto_search.php; look for the following code at line 97:

  $parts = explode(":",$pto_q);

...and REPLACE with:

  $pto_width = (isset($_GET["pto_width"])?intval($_GET["pto_width"]):"");
  $pto_ratio = (isset($_GET["pto_ratio"])?intval($_GET["pto_ratio"]):"");
  $pto_radial = (isset($_GET["pto_radial"])?intval($_GET["pto_radial"]):"");
  if ($pto_width && $pto_ratio && $pto_radial)
  {
    $pto_q = "size:".$pto_width."/".$pto_ratio."-".$pto_radial;
  }
  $parts = explode(":",$pto_q);

And then look for the following code at line 138:

    case "bw":

...and REPLACE with:

    case "size":
      $where = "sizes LIKE '%".$wpdb->escape($parts[1])."%'";
      break;
    case "bw":

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by koen on Mon, 2016-02-08 12:30

Thanks a lot David, I'm gonna give it a try!