You are here:  » PTO Shortcode for search in multiple fields


PTO Shortcode for search in multiple fields

Submitted by nanaz on Fri, 2017-10-13 12:51 in

Hi David,

Can you please explain how I can further refine PTO search? I've searched but just can't find it, sorry if it has already been answered somewhere.

The site is about watches, clocks, watchwinders etc and I'm in the process of changing the existing feedparser to Pricetapestry. I will mostly be using the PT shortcode in already existing, static WP pages because of the good SEO ranking the site built over the last years.

As you see on an already existing, static WP page like http://www.leukehorloges.nl/dameshorloges/bering there are only Ladies (Dames) watches of this brand, so I need to recreate this in PT.

The custom field 'gender' has already been created.

Shortcode could be something like:

[pto search="category: Watches" "brand:Xxx" "gender:Dames"]

Hope you can help me out again and thank you,

Marlies

Submitted by support on Fri, 2017-10-13 12:58

Hello Marlies,

The merchant/category/brand operators can already be included in a single query / shortcode by combining for example;

[pto search="merchant:Merchant Name:category:Category Name"]

To add your custom field gender, edit pto_search.php and look for the following code beginning at line 132:

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

...and REPLACE with:

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

And you'll then be able to use:

[pto search="category:Watches:brand:Xxx:gender:Dames"]

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by nanaz on Fri, 2017-10-13 13:51

Hi David,

So happy I've got this working now!

I had already changed the array in pto_search.php so it was only a question of getting the shortcode right.

Is it also possible to add another gender parameter?

[pto search="category:Watches:brand:Xxx:gender:Dames,Unisex"]

And of course another question: as I have added a custom 'gender' field, it would be great if I could use Gender Mapping in the same way as Brand (or Category) Mapping.

I already added a Custom gender field in Product mapping as described in https://www.pricetapestry.com/node/5794, but that doesn't really fit my needs.

Thank you again!

Cheers, Marlies

Submitted by support on Fri, 2017-10-13 14:14

Hello Marlies,

To enable comma separated multiple values (logic OR) for each field, first edit pto.php and look for the following code at line 500:

  $pto_q = (isset($pto_q)?pto_common_normalise($pto_q,":\.\/"):"");

...and REPLACE with:

  $pto_q = (isset($pto_q)?pto_common_normalise($pto_q,":\.\/,"):"");

And then edit pto_search.php and look for the following code at line 158:

        $where .= " ".$field." = '".esc_sql($parts[$i])."' ";

...and REPLACE with:

        $wheres = array();
        $values = explode(",",$parts[$i]);
        foreach($values as $value)
        {
          $wheres[] = $field." = '".esc_sql($value)."'";
        }
        $where .= "(".implode(" OR ",$wheres).")";

Regarding mapping for custom fields, I have created an admin extension that is a generic mapping module for any custom field - if you could email me admin/admin_header.php from the associated Price Tapestry installation I'll forward that for you to try...

Cheers,
David.
--
PriceTapestry.com

Submitted by nanaz on Fri, 2017-10-13 14:33

Thanks David, it works like a charm.

You really helped me a lot, thank you again for your continuing support!
I mailed you the file.

Cheers and have a great weekend,

Marlies