You are here:  » select on two or more words 'exact'

select on two or more words 'exact'

Submitted by presentguy on Sat, 2014-05-10 09:22 in

Hello all,

suppose you have this query as a customer to use in the sidebar-widget:
1. a boot
2. has to have a wedge or high heels, not a flat heel, no shoes with a wedge

or a ladies shoe like:
1. pumps
2. has to have a purple color.

Directly on the database, I use a query like boot%high heels and a pump%purple|purple pump.

Translated from MySql : % = a joker sign, sais there may be more characters between the two words, still in the same order !
Therefore in the second example: the sign | wich sais two queries, the first or the second.
Mostly this works.

In the widget, more words than one will seperatly used for searching, mostly not the selection I want.

But I want only boots with a wedge, or a blue pump.
( not alfa characters are wiped out and mostly I added the color/heel to the name/title during import)

Some wizard on this, or : only want what is possible ?? ;-)

Submitted by support on Sun, 2014-05-11 11:23

Hi presentguy,

It's straight forward to "convert" the Sidebar Filters widget into an "Advanced" search form (displayed on all pages, not just search results), which sounds like it might be very close if not exactly what you're after, so that a user can enter keywords but also select a category or brand etc.

To do this, in pto_search.php look for the following code beginning at line 1006:

    if (!isset($pto_searchWhere)) return;
    if ("/".$pagename != $pto_config_permalink) return;

...and REPLACE with the single line:

    if (!isset($pto_searchWhere)) $pto_searchWhere = " 1 ";

Alongside the code modification, to complete the conversion, from /wp-admin/ > Settings >, scroll down to the Main / Search Filters Widget template, and look for the following code near the beginning of the template body:

<input type='hidden' name='pto_q' value='%PTO_Q%' />

...and REPLACE with:

Keywords:<br />
<input type='text' name='pto_q' value='%PTO_Q%' />

Finally, towards the end of the template, the default submit button uses "Apply" as the label;

<input type='submit' value='Apply' />

...REPLACE with:

<input type='submit' value='Search' />

...or as required / appropriate for your site...


Submitted by presentguy on Mon, 2014-05-12 09:12

Hi David, I'm affraid I don't fully understand.

This is what we have now in the Search Widget Template partly translated in Dutch :

<div class='pto_search_filters_widget' style="background-color:#F2C778;padding-left:10px;border:3px orange outset;"><br /><br />
<form method='GET' action='%ACTION%'>
<strong>Wat wilt u vinden : </strong>
<input style="width:173px;" type='text' name='pto_q' value='%PTO_Q%' />
<br />Webwinkel :<br />
<select name='pto_merchantFilter'>
  <option value=''>All</option>
<br />
<br />Artikel Categorie:<br />
<select name='pto_categoryFilter'>
  <option value=''>All</option>
<br />
<br />Merk :<br />
<select name='pto_brandFilter'>
  <option value=''>All</option>
<br />
<br />Prijs begrenzing vanaf :<br />
%PTO_CURR%<input style="width:58px;" type='text' class='pto_search_filters_widget_price' name='pto_minPrice' value='%PTO_MINPRICE%' />
%PTO_CURR%<input style="width:58px;" type='text' class='pto_search_filters_widget_price' name='pto_maxPrice' value='%PTO_MAXPRICE%' />
<br /><br />
<input style="width:180px;font-weight:bold;" type='submit' value='Zoek NU' />
</form><br /><br />

I changed the line in pto_search.php and then .. ( but not different from yesterday and before [ ;-) ]

I put as search terms in the first line : 'pumps blauw'

I get : watershoe blue , clog blue, ladies pumps red

Indeed, input in reverse : blauwe pumps ( should be recognized as blauw pump )
consistent (!) pump but as colors : red, green, blue, orange, roze, white and so on

we cannot force customers think like a webtool, so we have to make a translation-function in my point of view.


I do have the colors in the field name, but it would probably be better to take a new custom column with the name 'color' in the pt_products table ?

Submitted by support on Mon, 2014-05-12 16:05

Hi presentguy,

Ah OK, how about then instead, extending the "search description" functionality to also include category, brand, and any custom fields as required.

It looks like you're creating niche installations, so try this method first, but if it looks like it's causing performance issues then we can extend the modification and create a FULLTEXT index against more fields.

To try the basic search method first, first go to /wp-admin/ > Settings > and under the External section, set $config_useFullText to FALSE, and $config_searchDescription to TRUE.

Then, in the plugin file pto_search.php, look for the following code at line 204:

  $where .= " OR description LIKE '%".$wpdb->escape($word)."%'";

...and REPLACE with;

  $where .= " OR description LIKE '%".$wpdb->escape($word)."%'";
  $where .= " OR category LIKE '%".$wpdb->escape($word)."%'";
  $where .= " OR brand LIKE '%".$wpdb->escape($word)."%'";

Of course, any additional custom fields can be added - just copy one of the above lines and insert into that block of code. You might also want to _exclude_ the description line - simply comment out or delete depending on how you find the results...

Hope this helps!


Submitted by presentguy on Mon, 2014-05-12 21:09

Hi David,

What I have done :
[1] reset the widget line in pto-search : if (!isset($pto_searchWhere)) $pto_searchWhere = " 1 ";

[2] in dashboard settings $config_useFullText to false
$config_searchDescription to TRUE

[3] in pto_search +/- 204 $where .= " OR description LIKE '%".$wpdb->escape($word)."%'";
the other 2 commented out for the time being.

The result is

on query 'blauwe pumps' : blue pump in many blue colors , but all different from :

on guery 'pumps blauw' : pumps blue in many blue colors, different from the first collection.

so far so good ;-)

BUT ....... we have to be customer / visitor friendly

I'm looking for : bringing up a collection 'blue pumps' AND 'pumps blue' for this lady.

IF I understand this function :

        $wheres = array();
        foreach($words as $word)
          $where = "(";
          $where .= "search_name LIKE '%".$wpdb->escape($word)."%'";
          if ($pto_config_searchDescription)

Because foreach starts over and over, the sequence with "blue and pump" remains the same.
204=230 $words : Array ( [0] => pumps [1] => blauw )

A reverse-array (in $contra_word) would be handy for a second array, so this would be possible (??) :

where search_name LIKE '%".$wpdb->escape($word)."%'" AND search_name LIKE '%".$wpdb->escape($contra_word)."%'"


search_name LIKE '%".$wpdb->escape($contra_word)."%'" AND search_name LIKE '%".$wpdb->escape($word)."%'"

if count($word) is a couple ofcourse. But what if there are 3+ ??

It's far too difficult for me :-)

But that's what I'm looking for ....

Submitted by presentguy on Tue, 2014-05-13 12:05

Perhaps indeed a better idea to extend the widget form with an choise on color ?

Submitted by support on Tue, 2014-05-13 12:11

Hi presentguy,

Sure - custom filters are straight forward to add but it's a bit of a copy / paste job. Assuming you have added the custom field `color` as per the standard instructions then if you'd like to email me your plugin files:


...and also the associated Price Tapestry installation's config.advanced.php (for reference) I'll add that for you, and mark-up so that it's easy for you to add additional custom filters if required...