You are here:  » pto search shortcode - search within category/merchant

Active Forum Topics


pto search shortcode - search within category/merchant

Submitted by nanaz on Fri, 2018-02-09 16:55 in

Hi David,

Hope you are well!

I added a function in PTO 2.0, derived from https://www.pricetapestry.org/node/514 to make it possible in shortcode pto_search to search within a category or merchant. It works great, but the unset function doesn't work, the category or merchant parameter remains set and active. Not nice on a blogpage with all different kinds of shortcodes on 1 page.

[pto search="searchterm" incategory="something" results="12" sort="random"]

I added in pto.php

<?php
if (isset($atts["inmerchant"]))
    {
      global 
$pto_searchIncludeMerchant;
      
$pto_searchIncludeMerchant $atts["inmerchant"];
    }
 if (isset(
$atts["incategory"]))
    {
      global 
$pto_searchIncludeCategory;
      
$pto_searchIncludeCategory $atts["incategory"];
    }
?>

and in pto_search.php:

<?php
global $pto_searchIncludeMerchant;
  if (isset(
$pto_searchIncludeMerchant))
  {
    
$ins = array();
    
$merchants explode(",",$pto_searchIncludeMerchant);
    foreach(
$merchants as $merchant)
    {
      
$ins[] = "'".$wpdb->escape($merchant)."'";
    }
    
$pto_searchWhere .= " AND merchant IN (".implode(",",$ins).") ";
    unset(
$pto_searchIncludeMerchant);
  }
  global 
$pto_searchIncludeCategory;
  if (isset(
$pto_searchIncludeCategory))
  {
    
$ins = array();
    
$categories explode(",",$pto_searchIncludeCategory);
    foreach(
$categories as $category)
    {
      
$ins[] = "'".$wpdb->escape($category)."'";
    }
    
$pto_searchWhere .= " AND category IN (".implode(",",$ins).") ";
    unset(
$pto_searchIncludeCategory);
  }
?>

Hope you can help!

Kind regards, Marlies

Submitted by support on Sat, 2018-02-10 07:49

Hello Marlies,

It should just be a case of unsetting $pto_searchWhere at the end of the pto_search() function so if you edit pto_search.php, locate the pto_search() function and at the end (around line 411 in the distribution) will be;

  return $html;

....REPLACE with:

  unset($pto_searchWhere);
  return $html;

Cheers,
David.
--
PriceTapestry.com

Submitted by nanaz on Sat, 2018-02-10 10:23

Hi David,

Thank you for a weekend answer! Sorry to say it's not working, I also added the other 2 there too - just to be sure -

<?php
unset($pto_searchWhere);
unset(
$pto_searchIncludeCategory);
unset(
$pto_searchIncludeMerchant);
?>

but the $pto_searchWhere value is not released.

There are extra functionalities added to pto_search.php, but as far as I can see they shouldn't have an affect on $pto_searchWhere.

Do you have an idea?

Thank you again,

Marlies

Submitted by support on Sat, 2018-02-10 11:39

Hello Marlies,

Please could you email me modified pto.php and pto_search.php and also an example of a shortcode that you're using and I'll check it out further for you...

Thanks,
David.
--
PriceTapestry.com