You are here:  » Shortcode Search Filter


Shortcode Search Filter

Submitted by stew on Tue, 2016-03-15 22:02 in

Hi David,

Hope all's going well, at present am trying to display only 'Male' or 'Female' products from a datafeed.

The datafeed has a gender column title of "Gender" and row entry of "M".

Thus have created a dbmod.php as per: http://www.pricetapestry.com/node/3094

to create "Gender".

Gender now appears when I import the feed, I can map "Gender" to the column entry when importing.

The next step I'm having issues with is displaying the results.

For example I'm trying to show all mens briefs and not womens etc.

Im using the shortcode: [pto search="gender:M briefs"]

But no results are displaying, any ideas?

I also tried finding and replacing 'M' for 'male' in case the letter count was too short and using:

[pto search="gender:male briefs"]

but no luck as yet,

Will see what you think, I may have the shortcode completely wrong here..

Submitted by support on Wed, 2016-03-16 10:27

Hello Stew,

You can construct a multi-field search query including name with a small modification to pto_search.php. First look for the following code at line 107:

  $fields = array("merchant","category","brand");

...and REPLACE with:

  $fields = array("merchant","category","brand","gender");

Then look for the following code at line 131:

  $where .= " ".$field." = '".$wpdb->escape($parts[$i])."' ";
  $first = FALSE;

...and REPLACE with:

  if ($field)
  {
    $where .= " ".$field." = '".$wpdb->escape($parts[$i])."' ";
  }
  else
  {
    $where .= " name LIKE '%".$wpdb->escape($parts[$i])."%' ";
  }
  $field = "";
  $first = FALSE;

With that in place, you'll then be able to construct a search shortcode for example;

[pto search="gender:M:briefs"]

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by stew on Wed, 2016-03-16 22:01

Hi David,

Many thanks for that, I implemented those adjustments into pto_search.php and tried the shortcode:

[pto search="gender:M:briefs"]

but am getting: "Sorry, there are no results to display."

Not sure if it is because we implemented the full text search previously, have tried for example [pto search="gender:M:ft:briefs"] but no luck.

I've checked the feed and the Gender is 'M'

Any ideas here?

Thanks,

Stew

Submitted by support on Thu, 2016-03-17 09:03

Hello Stew,

If you wanted to give it a go with ft support instead of a basic LIKE query, as the first REPLACement, use:

  $fields = array("merchant","category","brand","gender","ft");

And for the second:

  if ($field == "ft")
  {
    $where .= " MATCH name AGAINST ('%".$wpdb->escape($parts[$i])."') ";
  }
  elseif ($field)
  {
    $where .= " ".$field." = '".$wpdb->escape($parts[$i])."' ";
  }
  else
  {
    $where .= " name LIKE '%".$wpdb->escape($parts[$i])."%' ";
  }
  $field = "";
  $first = FALSE;

And then use exactly as per your example;

[pto search="gender:M:ft:briefs"]

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by stew on Mon, 2016-03-21 19:17

David,

Many thanks for that, I've implemented those two new sections, but currently getting:

"Sorry, there are no results to display."

with

[pto search="gender:M:ft:briefs"]

I think I've implemented all as needed - any ideas of anything else that might need tweaking?

Stew

Submitted by support on Tue, 2016-03-22 09:25

Hi Stew,

Sorry about that, please could you email me your modified pto_search.php and I'll check it through on my test server...

Thanks,
David.
--
PriceTapestry.com