I don't get that problem with a test set based on your snippet code above and using a multiple listbox TV prDiets with options
All Dietary Needs==||None==None||Soy Free||Vegan||Dairy Free||Low Glycemic||Gluten Free
Try inserting
return print_r($filter, true);
as a line before your existing
return , to see what's being fed to Ditto.
I can see a problem with the way you are building the filter string. The Company, Category and ratings output is being added with a bar at the start if required. Your multiselect is adding a bar afterwards and removing the surplus one. So select one Category and one Dietary Need, and you have two filters running into each other with no bar between. You could use the same method of adding a bar at the start when adding to a nonempty string in your loop (also I've found you need to test for an empty element zero in the array, rather than an empty array):
if (!empty($_GET['prDiets'][0])) {
foreach($_GET['prDiets'] as $key=> $value) {
// loop thru and build the filter for ditto
$filter .= (empty($filter)?"":"|") . 'prDiets,' . $value . ',7';
}
}
or use an array to build the set of filters and implode them with a bar (much more respectable, IMHO):
<?php
global $modx;
$filter = array();
if (!empty($_GET['prCompany'])) {
$filter[] = "tvprCompany," . mysql_escape_string($_GET['prCompany']) . ",1";
}
if (!empty($_GET['prCategory'])) {
$filter[] = "tvprCategory," . mysql_escape_string($_GET['prCategory']) . ",1";
}
if (!empty($_GET['prRating'])) {
$filter[] = "tvprRating," . mysql_escape_string($_GET['prRating']) . ",1";
}
// have to check element 0 of the prDiets array for empty, not the array itself
if (!empty($_GET['prDiets'][0])) {
foreach($_GET['prDiets'] as $key=> $value) {
$filter[] = 'prDiets,' . $value . ',7';
}
}
$filter = implode('|', $filter);
$output = $modx->runSnippet('Ditto', array( 'tpl'=>'productReviewList', 'filter'=>$filter, 'noResults'=>'There are no products matching your selections. Please try different criteria.'));
return $output;
?>
And a couple of logic problems: isn't "None" the same as "no selection"? That is, you need to give it a value of empty, unless you want to include "None" as a feature of every product's Dietary Needs. And if you select a three-star rating, don't you want to include items with a higher rating? (I think that make the comparison mode 3 rather than 1 for the rating filter).
:) KP