You are here:  » Logging views querys in wordpress

Support Forum



Logging views querys in wordpress

Submitted by michael on Thu, 2012-07-19 17:51 in

Hi David
i have managed to get both search and views logging set up in price tapestry. not sure of the node i followed for logging searches but its in table querylog without pt prefix, i followed node 2446 to get view logs set up allthough i had to change name to normalised_name in products.php to get it working

is there anyway to add similar functionality to the wordpress plugin, i.e logging of searches and views i tried:
on line 280 pto_products.php but it didn't work

     $sql = "UPDATE `".$pto_config_databaseTablePrefix."products` SET views = views + 1 WHERE normalised_name = '".$wpdb->escape($pto_product)."'";
    database_queryModify($sql,$result);

King Regards

Michael

Submitted by support on Fri, 2012-07-20 19:50

Hello Michael,

Very nearly, but you need to use the WordPress db library rather than the Price Tapestry standalone verison - have a go with:

$sql = "UPDATE `".$pto_config_databaseTablePrefix."products` SET views = views + 1 WHERE normalised_name = '".$wpdb->escape($pto_product)."'";
$wpdb->query($sql);

Cheers,
David.
--
PriceTapestry.com

Submitted by michael on Sun, 2012-07-22 04:17

hi david thanks again that worked when i added it to pto_product.php line 424 im having a problem getting the output on the index page of the wp site not inside pricetapestry plugin so far this is what ive got:

  $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` ORDER BY views DESC LIMIT 10";
  if ($wpdb->query($sql,$products))
  {
    print "<h4>Top 10 Viewed Products</h4>";
    print "<ul>";
    foreach( $products as $product)
    {
      if ($pto_config_useRewrite)
      {
        $href = $pto_config_baseHREF."product/".tapestry_hyphenate($product["name"])."/";
      }
      else
      {
        $href = $pto_config_baseHREF."shopping/?pto_q=".urlencode($product["name"]);
      }
      print "<li><a href='".$href."'>".$product["name"]."</a></li>";
    }
    print "</ul>";
  }

i can get it as far as the foreach but then i get a Invalid argument supplied for foreach() error

Submitted by support on Sun, 2012-07-22 10:13

Hi Michael,

Because the WordPress database library is object orinted the variables have to be used slightly differently; have a go with;

$sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` ORDER BY views DESC LIMIT 10";
  if ($wpdb->query($sql))
  {
    print "<h4>Top 10 Viewed Products</h4>";
    print "<ul>";
    foreach($wpdb->last_result as $product)
    {
      $href = pto_common_productHREF($product);
      print "<li><a href='".$href."'>".$product->name."</a></li>";
    }
    print "</ul>";
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by michael on Sun, 2012-07-22 20:32

thanks again for all your help david that got it sorted