You are here:  » Product and Merchant Count Shortcode


Product and Merchant Count Shortcode

Submitted by support on Tue, 2014-02-18 12:41 in

Hi everyone,

I've had a couple of enquiries regarding how to show the total product count, number of merchants etc. within WordPress, so here is the code to add an "info" shortcode. In the main plugin file pto.php look for the following code at line 406:

  case "atoz":

...and REPLACE with:

  case "info":
    switch($v)
    {
      case "numProducts":
        $sql = "SELECT COUNT(*) AS numProducts FROM `".$pto_config_databaseTablePrefix."products`";
        $wpdb->query($sql);
        $html .= $wpdb->last_result[0]->numProducts;
        break;
      case "numMerchants":
        $sql = "SELECT COUNT(DISTINCT(merchant)) AS numMerchants FROM `".$pto_config_databaseTablePrefix."products`";
        $wpdb->query($sql);
        $html .= $wpdb->last_result[0]->numMerchants;
        break;
    }
  case "atoz":

To use, simply insert the short codes as required within a page or post body e.g:

Comparing [pto info="numProducts"] products from [pto info="numMerchants"] stores!

There are also a number of plugins that allow shortcodes to be used elsewhere within WordPress generated content for example Shortcodes in Sidebar Widgets...

Cheers,
David
--
PriceTapestry.com