Similar type function I wrote is count_user_field.
May be of use to someone else out there also, I needed a custom function to display how many listings had an admin defined extra field set to a certain value in my case the field was 'Status' and the value was 'Reused' you can pass any extra field and value to the function though.
PHP Code:
<?php
function smarty_function_count_user_field($params, $smarty)
{
global $db;
foreach ($params as $_key=>$_value)
{
switch ($_key)
{
case 'fldname':
$$_key = (string)$_value;
break;
case 'fldvalue':
$$_key = (string)$_value;
break;
}
}
//Get field ID from class_fields
$sSQL = "SELECT fID FROM ".PREFIX."fields WHERE fNAME = '$fldname'";
$result=$db->query($sSQL);
$fID=$result->fetch();
//Count number of ads with field set to desired status
$sSQL="SELECT COUNT(*) AS total FROM ".PREFIX."products,".PREFIX."products_fields WHERE id=pID AND expiration > NOW() AND display = 'Y' AND sValue = '$fldvalue'";
$result=$db->query($sSQL);
$rs=$result->fetch();
return $rs['total'];
}
?>
Copy and paste this code in a new file and save it as: function.count_user_field.php
Upload it to includes/templates/plugins/ directory
Finally to display the total add {count_user_field fldname=
YourExtraFieldName fldvalue=
YourFieldsValue} to your template file.
In my case call was;
{count_user_field fldname=Status fldvalue=Reused}
Hope it helps all the best,
Mully