You are here:  » Limit results presented in shortcodes


Limit results presented in shortcodes

Submitted by marco@flapper on Sat, 2012-02-04 06:26 in

How can I limit the results for the shortcodes?

I'm using:

[pto search=]

[pto related=]

Submitted by support on Sat, 2012-02-04 08:44

Hi Marco,

In order to preserve the existing default of 3 related products, in pto_product.php look for the following code at line 160:

$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".$wpdb->escape($product->name)."') AS relevance FROM `".$pto_config_databaseTablePrefix."products` WHERE ".$where." GROUP BY name ORDER BY relevance DESC LIMIT 3";

...and REPLACE with:

global $pto_config_relatedPerPage;
if (!isset($pto_config_relatedPerPage)) $pto_config_relatedPerPage = 3;
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".$wpdb->escape($product->name)."') AS relevance FROM `".$pto_config_databaseTablePrefix."products` WHERE ".$where." GROUP BY name ORDER BY relevance DESC LIMIT ".$pto_config_relatedPerPage;

Finally, in pto.php look for the following code at line 550:

        case "atoz":

...and REPLACE with:

        case "searchlimit":
          global $pto_config_resultsPerPage;
          $pto_config_resultsPerPage = $v;
          break;
        case "relatedlimit":
          global $pto_config_relatedPerPage;
          $pto_config_relatedPerPage = $v;
          break;
        case "atoz":

With that in place, you can now use, for example:

[pto searchlimit="5" search="Widgets"]

[pto relatedlimit="2" related="Blue Widget"]

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Tue, 2012-11-13 09:17

Hi,
I'm trying to bring this mod on to the latest version of the plugin 1.0 but it seems the code changed.

I could replace the part in pto_product.php but couldn't find the case "atoz": in pto_search.php.

And is there a limit possible too for [pto prices=] ?

Submitted by support on Tue, 2012-11-13 10:12

Hi Marco,

My apologies the modification referred to pto.php not pto_search.php (corrected and line number updated above).

Sure - the same trick can be applied to limit prices. Extend the above modification as follows:

        case "searchlimit":
          global $pto_config_resultsPerPage;
          $pto_config_resultsPerPage = $v;
          break;
        case "relatedlimit":
          global $pto_config_relatedPerPage;
          $pto_config_relatedPerPage = $v;
          break;
        case "pricelimit":
          global $pto_config_pricePerPage;
          $pto_config_pricePerPage = $v;
          break;
        case "atoz":

And then in pto_product.php look for the following code at line 280:

  $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` WHERE normalised_name = '".$wpdb->escape($pto_product)."' ORDER BY price";

...and REPLACE with;

  $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` WHERE normalised_name = '".$wpdb->escape($pto_product)."' ORDER BY price";
  global $pto_config_pricePerPage;
  if (isset($pto_config_pricePerPage))
  {
    $sql .= " LIMIT ".$pto_config_pricePerPage;
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Tue, 2012-11-13 20:49

Thanks.