Forum
Filtering a product page
I have run into an issue. I am trying to populate a page with correct products when someone clicks various boxes then hits the filter button.
Problem 1) basically the initial page load is great at marking only those checked on with this code
'filter' => 'Display',
'match' => 'eq',
'value' => 'true',
I run into a problem if someone uses the filter that it will display all products in the database even if Display is not = true
Problem 2) When filtering, if someone clicks a manufacturer say Tropitone and click Wrought Iron and clicks filter…it displays all the Tropitone furniture and all the Wrought Iron not just Wrought Iron by Tropitione.
So it needs to be a script that Manufactures are an “or†(to be able to pick more than one) then “and†style (which could be multiple) then “and†use (which could be multiple) then they would filter the results and it would return only those marked to be Displayed as described in problem 1.
Below is my filter code...any help would be great.
<?php
perch_content_create('Products', array(
'template' => 'grill_product_detail.html',
'multiple' => true,
'edit-mode' => 'listdetail',
));
$filters = array();
if(isset($_POST) && !empty($_POST))
{
if(!empty($_POST['mfg_list']))
{
foreach($_POST['mfg_list'] as $check)
{
$filters[] = array(
'filter'=>'manufacturer',
'match'=>'eq',
'value'=> $check
);
}
}
if(!empty($_POST['Gas']))
{
foreach($_POST['Gas'] as $check)
{
$filters[] = array(
'filter'=>'Gas',
'match'=>'eq',
'value'=> $check
);
}
}
if(!empty($_POST['Charcoal']))
{
foreach($_POST['Charcoal'] as $check)
{
$filters[] = array(
'filter'=>'Charcoal',
'match'=>'eq',
'value'=> $check
);
}
}
if(!empty($_POST['NaturalGas']))
{
foreach($_POST['NaturalGas'] as $check)
{
$filters[] = array(
'filter'=>'NaturalGas',
'match'=>'eq',
'value'=> $check
);
}
}
if(!empty($_POST['LPGas']))
{
foreach($_POST['LPGas'] as $check)
{
$filters[] = array(
'filter'=>'LPGas',
'match'=>'eq',
'value'=> $check
);
}
}
if(!empty($_POST['Carts']))
{
foreach($_POST['Carts'] as $check)
{
$filters[] = array(
'filter'=>'Carts',
'match'=>'eq',
'value'=> $check
);
}
}
if(!empty($_POST['Rubs']))
{
foreach($_POST['Rubs'] as $check)
{
$filters[] = array(
'filter'=>'Rubs',
'match'=>'eq',
'value'=> $check
);
}
}
if(!empty($_POST['Accessories']))
{
foreach($_POST['Accessories'] as $check)
{
$filters[] = array(
'filter'=>'Accessories',
'match'=>'eq',
'value'=> $check
);
}
}
}
// if we have filters selected process and display results
if(!empty($filters)){
perch_content_custom('Products', array(
'template' => 'grill_product_listing.html',
'filter' => $filters,
'match' => 'or',
'value' => 'true'
))
;
}
else
if (perch_get('s')) {
// Detail mode
perch_content_custom('Products', array(
'template' => 'grill_product_detail.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
));
} else {
// List mode
perch_content_custom('Products', array(
'template' => 'grill_product_listing.html',
'filter' => 'Display',
'match' => 'eq',
'value' => 'true'
));
}
?>
You can use an AND filter or an OR filter, but not both at once.
For the first item, can you show me the full function call?