View Single Post
  #1  
Old May 1st, 2011, 08:18 PM
meperez meperez is offline
 
Join Date: Mar 2011
Posts: 43
Default Dynamic Generation of Brand Filter

www.thekitchentool.com
Store Id: 30751

Hi Eric,

I have some hard-coded brand filters on each category and I'm trying to generate those dynamically so that I don't have to worry about them getting out of sync with the products. Based on other posts I saw, I gave it an initial try... and clearly my syntax is erroneous somewhere as the Brand Filter no longer shows up. I'm trying it on the Woks category under Cookware. Can you please help?

I added the following function to my functions.php:

//Function to Get Brands of Woks Category
function dfr_get_brands() {
global $wpdb;
$merchants = $wpdb->get_results("SELECT DISTINCT p.brand FROM ".$wpdb->prefix."dfr_shop_products p, ".$wpdb->prefix."wp_dfr_shop_p2c pc, ".$wpdb->prefix."wp_dfr_shop_cats c AND pc.cat_id = c.id AND c.name = \'Woks\' ORDER BY c.name, p.brand");
$list = array();
foreach ($brands as $brands) {
$list[$brands->brand] = $brands->brand;
}
return $list;
}

Then to the filter Widget, I added:

<div>
<form method="get">
<span>
<?php echo datafeedr_tools()->form_select("brand",
array(
"" => "All Brands",
?>
<?php
$brands = dfr_get_brands();
foreach ($brands as $brandname) {
echo '\"'$brandname'\" => \"'$brandname'\",';
}
?>
));
<input type="submit" value="Go" />
</span>
</form>
</div>

My goal is to generate the following code, for example:

<div>
<form method="get">
<span>
<?php echo datafeedr_tools()->form_select("brand",
array(
"" => "All Brands",
"All-Clad" => "All-Clad",
"Anolon" => "Anolon",
"Calphalon" => "Calphalon",
"Circulon" => "Circulon",
"Cuisinart" => "Cuisinart",
"Le Creuset" => "Le Creuset",
"West Bend" => "West Bend"
)); ?>
<input type="submit" value="Go" />
</span>
</form>
</div>