You are here:  » How do I display results in Wordpress from import fields I created myself


How do I display results in Wordpress from import fields I created myself

Submitted by Romac39 on Wed, 2012-03-07 13:26 in

Hi David,

As you know I recently made some filters for my travel website so I can search and display information like Region and City.
I also added Lodgement and Vacationtype now so people can search for All inclusive vacations or Wintersport vacations for instance. But how do I display all results from either of these added filters?
I think it must be something in the way the URL is formed? www.Domain.ext/?pto_q= and then something like &pto_regionFilter= perhaps?

Or do I need to make a dedicated page in Wordpress and amend "filter Base HREF" in the Pricetapestry files?

Regards,

Robert

Submitted by support on Wed, 2012-03-07 13:33

Hi Robert,

The Product/Main and Prices/Each (wp-admin > Settings > PriceTapestry.org) support the placeholder %DB_fieldname% so you could use in your templates %DB_region% for example. If you need support for that placeholder in any other templates let me know and I can work out the changes for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by Romac39 on Wed, 2012-03-07 17:04

I dont think I'm grasping what your telling me. From my homepage I want to link to a list of search results of all vacations that are are Wintersport vacations. I created an extra filter for vacation type and imported a feed with a column header VacationType and some of the fields in the records of the feed have Wintersport as a value. What would be the URL if I want to make a straight link from my homepage to that list of search results? Can you give an example?

Submitted by support on Wed, 2012-03-07 18:51

Hello Robert,

Ah yes you can do this, all you need to do is add a search: handler for the new field. In pto_search.php you will find this code at starting at line 167:

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

REPLACE with:

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

...and then you can create a link to

/shopping/?pto_q=vacationtype:Wintersport

(and of course you can add search operators for any other custom fields in exactly the same way)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Romac39 on Thu, 2012-03-08 06:36

Thanks David,

It works very well.

Robert

Submitted by richard on Thu, 2014-01-30 10:38

Hi David,

After a number of years on another project, I cannot believe how you have made PT even better. I did not think it was possible! Thank you.

I am using PT & wordpress plugin and would like to include another fieldname in the search results. I see the templates work ok for the main product & prices section but not search results.

Could you point me in right direction please.

Many thanks

Richard

Submitted by support on Thu, 2014-01-30 12:07

Hi Richard,

Thank you for your comments!

To include custom fields in Search Results / Each, first the re-query in pto_search.php will need to be extended to include all fields. To do this, look for the following code at line 357:

  $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating FROM `".$pto_config_databaseTablePrefix."products` WHERE id IN (".$in.")";

...and REPLACE with:

  $sql2 = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` WHERE id IN (".$in.")";

Then look for the following code at line 382:

  $pto_searchResults[$k]->rating = $rows3[$product->id]->rating;

...and REPLACE with:

  $pto_searchResults[$k]->rating = $rows3[$product->id]->rating;
  foreach($rows3[$product->id] as $k2 => $v2)
  {
    if (!isset($pto_searchResults[$k]->$k2))
    {
      $pto_searchResults[$k]->$k2 = $v2;
    }
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Thu, 2014-01-30 12:50

Hi David

Many thanks.

I get this error message:

Warning: Invalid argument supplied for foreach() in /homepages/1/xxxxxxxxxx/wp-content/plugins/pto/pto_search.php on line 383

Any ideas why?

Regards

Richard

Submitted by support on Thu, 2014-01-30 13:17

Hi Richard,

Sorry about that - the final replacement was overwriting the $k variable - corrected to use $k2 and $v2 above...

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Thu, 2014-01-30 14:06

Great, works perfectly :)

Thank you.

Submitted by richard on Thu, 2014-01-30 19:29

Hi David

Just checking through site and I see that the extra field that I added from above in the search results does not appear in the related product section on the product page.

What would I need to amend to pull the new field through for this section?

Regards

Richard

Submitted by support on Fri, 2014-01-31 09:13

Hi Richard,

Almost the same modification is required in pto_product.php. In that file, look for the following code at line 230:

    $sql2 = "SELECT name,normalised_name,image_url,description,price,rating,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$pto_config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";

...and REPLACE with:

    $sql2 = "SELECT *,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$pto_config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";

And then look for the following code at line 255:

  $pto_searchResults[$k]->rating = $rows3[$product->name]->rating;

...and REPLACE with:

  $pto_searchResults[$k]->rating = $rows3[$product->name]->rating;
  foreach($rows3[$product->name] as $k2 => $v2)
  {
    if (!isset($pto_searchResults[$k]->$k2))
    {
      $pto_searchResults[$k]->$k2 = $v2;
    }
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Fri, 2014-01-31 09:38

Thank you.

I am going to have to spend some time getting to know my way around the pto files!

Also, in the above solution you refer to pto_strong.php as opposed to pto_product.php

Regards

Richard

Submitted by support on Fri, 2014-01-31 10:01

Ooops! Typing too fast! Glad you're sorted...

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Tue, 2014-02-25 18:14

Hi David

I would like to extend the search shortcode so that I can include the keyword as well as merchant.

E.g.
Merchant = Currys
Keyword = laptop

So shortcode would look like:

[pto search="merchant:currys:keyword:laptop"]

How would I modify pto_search.php to enable me to do the above?

Regards

Richard

Submitted by support on Tue, 2014-02-25 18:17

Hi Richard,

No problem! In pto_search.php look for the following code around line 107:

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

...and REPLACE with:

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

And then the following code at line 131:

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

...and REPLACE with:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Tue, 2014-02-25 18:23

WOW, that was a quick reply.

Works well, thank you

Submitted by richard on Fri, 2014-03-07 11:48

Hi David

I wish to create a wordpress page dedicated to brands relevant to a particular category, e.g. toys.

I think the [pto search="category:Toys"] function could be adapted to achieve this but I am not sure how I can generate just a list of brand name links without affecting the layout of standard search results.

So page could have the following:

    Barbie Doll
    Lego
    Mondo Motors
    Power rangers

What do I need to do to enable the different page layout to the standard search results?

Many thanks

Richard

Submitted by support on Fri, 2014-03-07 11:59

Hi Richard,

An easy way to do this would be to modify the atoz shortcode to enable filtering by category. To try this, edit pto_atoz.php and look for the following code at line 84:

  $sql = "SELECT DISTINCT(".$module.") FROM `".$pto_config_databaseTablePrefix."products` WHERE ".$module." <> '' ORDER BY ".$module;

...and REPLACE with:

  $parts = explode(":",$module);
  if (count($parts)>1)
  {
    $module = $parts[0];
    $where = " AND ".$parts[1]." = '".$wpdb->escape($parts[2])."'";
  }
  else
  {
    $where = "";
  }
  $sql = "SELECT DISTINCT(".$module.") FROM `".$pto_config_databaseTablePrefix."products` WHERE ".$module." <> '' ".$where." ORDER BY ".$module;

And then use the shortcode e.g.

[pto atoz="brand:category:Toys"]

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Fri, 2014-03-07 12:12

Hi David

Thank you.

Unfortunately [pto atoz="brand:category:Socks"] does not filter the brands to just Sock brands - I appear to still get all brand names

Regards

Richard

Submitted by support on Fri, 2014-03-07 12:38

Hi Richard,

I've modified the replacement above, please have a go with this version which is working OK on my test server, however the previous version should have returned nothing rather than everything so I'm wondering whether the upload of the modified file might not have completed, or whether you were viewing a cached page - if still no joy with this modification let me know and I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Fri, 2014-03-07 12:45

Hi David,

New code works a treat.

Thank you

Regards

Richard