You are here:  » Exclude Merchant Feed In Results With Individual Short Code Query


Exclude Merchant Feed In Results With Individual Short Code Query

Submitted by stew on Fri, 2017-01-27 11:31 in

Hi David,

Hope all's going well.

Wondering if you can help, I'm trying to exclude a particular merchant from a list of results within a WP page, I'm currently using:

[pto search="ft:shorts,-brief -sports"]

is there a way to exclude a merchant feed with this type of query, for example:

[pto search="ft:shorts,-brief -sports, exclude-merchant:Merchant Name"]

or similar?

Thanks,

Stew

Submitted by support on Fri, 2017-01-27 12:22

Hello Stew,

It would be straight forward to pass through as a separate attribute - to try this edit pto.php and look for the following code at line 400:

    if (isset($atts["maxprice"])) $pto_maxPrice = $atts["maxprice"];

...and REPLACE with:

    if (isset($atts["maxprice"])) $pto_maxPrice = $atts["maxprice"];
    if (isset($atts["excludemerchant"]))
    {
      global $pto_searchExcludeMerchant;
      $pto_searchExcludeMerchant = $atts["excludemerchant"];
    }

Then edit pto_search.php and look for the following code at line 227:

  $pto_searchWhere = $where.$priceWhere;

...and REPLACE with:

  $pto_searchWhere = $where.$priceWhere;
  global $pto_searchExcludeMerchant;
  if (isset($pto_searchExcludeMerchant))
  {
    $pto_searchWhere .= " AND merchant <> '".$wpdb->escape($pto_searchExcludeMerchant)."' ";
    unset($pto_searchExcludeMerchant);
  }

Then use as your shortcode;

[pto search="ft:shorts,-brief -sports" excludemerchant="Merchant Name"]

Cheers,
David.
--
PriceTapestry.com

Submitted by stew on Fri, 2017-01-27 16:27

All now working - many thanks!!

One thing though, if I wanted to exclude more than one merchant - is that possible?

Stew

Submitted by support on Fri, 2017-01-27 16:43

Hi Stew,

Sure - as an alternative to the above modification to pto_search.php, have a go with:

  $pto_searchWhere = $where.$priceWhere;
  global $pto_searchExcludeMerchant;
  if (isset($pto_searchExcludeMerchant))
  {
    $ins = array();
    $merchants = explode(",",$pto_searchExcludeMerchant);
    foreach($merchants as $merchant)
    {
      $ins[] = "'".$wpdb->escape($merchant)."'";
    }
    $pto_searchWhere .= " AND merchant NOT IN (".implode(",",$ins).") ";
    unset($pto_searchExcludeMerchant);
  }

And then specify the excludemerchants value as comma separated list e.g.

[pto search="ft:shorts,-brief -sports" excludemerchant="Merchant 1,Merchant 2"]

Cheers,
David.
--
PriceTapestry.com

Submitted by stew on Tue, 2017-01-31 21:34

Hi David,

Brilliant - many thanks for that.

One other query on this, is there a way to exclude products from a certain category also?

Cheers

Stewart

Submitted by support on Wed, 2017-02-01 09:50

Hi Stewart,

Sure - you can do exactly the same for categories. At the same point in the code for the excludemerchant modification, in pto.php add:

    if (isset($atts["excludecategory"]))
    {
      global $pto_searchExcludeCategory;
      $pto_searchExcludeCategory = $atts["excludecategory"];
    }

And in pto_search.php, add:

  global $pto_searchExcludeCategory;
  if (isset($pto_searchExcludeCategory))
  {
    $ins = array();
    $categories = explode(",",$pto_searchExcludeCategory);
    foreach($categories as $category)
    {
      $ins[] = "'".$wpdb->escape($category)."'";
    }
    $pto_searchWhere .= " AND category NOT IN (".implode(",",$ins).") ";
    unset($pto_searchExcludeCategory);
  }

And example usage;

[pto search="ft:shorts,-brief -sports" excludemerchant="Merchant 1,Merchant 2" excludecategory="Category 1,Category 2"]

Cheers,
David.
--
PriceTapestry.com

Submitted by stew on Fri, 2017-02-03 14:22

Hi David,

Brilliant, many thanks for going through that, got it,

Thanks,

Stew