$c = $modx->newQuery('Products');
$c->where(array('cat'=>'NIC','OR:cat:='=>'NIR'));This question has been answered by BobRay. See the first response.
It sounds like you just need a dropdown, radio options, or checkboxes in a form. Make the where() statement based on how they're set.Hi Bob,
Do you have a user interface in mind?
How do the current radio buttons work -- JavaScript or form/reload?
<?php
$path = MODX_CORE_PATH . 'components/table/';
$result = $modx->addPackage('table',$path .
'model/','pre_');
if (! $result) {
return 'failed to add package';
}
$modx->runSnippet('RadioButtons');
$modx->runSnippet('FeetInch');
$fi = new FeetInch($modx);
$sortby = 'cat';
$checked = 'checked="checked"';
if (isset($_POST['sort_method']) && (! empty($_POST['sort_method']))) {
$sortby = $_POST['sort_method'];
}
$modx->setPlaceholder($sortby . '_checked', $checked);
$c = $modx->newQuery('Products');
$c->sortby($sortby, 'ASC');
$c->where(array('cat'=>'NIC','OR:cat:='=>'NIR'));
$products = $modx->getCollection('Products',$c);
foreach($products as $product) {
.....
}
$fields = $product->toArray();
$output .= $modx->getChunk('ShowNiches', array_merge($fields, array(.....)));
}
return $output;<form action="[[~[[*id]]]]" method="POST"> <p id="radio"> <input type="radio" name="sort_method" id="radio4" value="cat" onChange="this.form.submit();" /> <label for="radio4">Reset Sorting</label> <input type="radio" name="sort_method" [[+width_checked]] id="radio3" value="width" onChange="this.form.submit();" /> <label for="radio3">Sort by Width</label> <input type="radio" name="sort_method" [[+height_checked]] id="radio2" value="height" onChange="this.form.submit();" /> <label for="radio2">Sort by Height</label> <input type="radio" name="sort_method" [[+depth_checked]] id="radio1" value="depth" onChange="this.form.submit();" /> <label for="radio1">Sort by Depth</label> </p> <p> </p> </form>
if ($nicCheckbox && (! $nirCheckbox)) {
$c->where(array('cat'=>'NIC'));
} elseif ($nirCheckbox && (! $nicCheckbox)) {
$c->where(array('cat'=>'NIR'));
} else { /* default, show both */
$c->where(array('cat'=>'NIC','OR:cat:='=>'NIR'));
}$sortby = 'itemno';
if (isset($_POST['sort_method']) && (! empty($_POST['sort_method']))) {
$sortby = $_POST['sort_method'];
}
$checkbox1 = $_POST['check_cat1'];
$checkbox2 = $_POST['check_cat2'];
$c = $modx->newQuery('Products');
$c->sortby($sortby, 'ASC');
if ($checkbox1 && (! $checkbox2)) {
$c->where(array('cat'=>'BRA'));
} elseif ($checkbox2 && (! $checkbox1)) {
$c->where(array('cat'=>'COR'));
} else {
$c->where(array('cat'=>'BRA','OR:cat:='=>'COR'));
}
$checked = 'checked="checked"';
$modx->setPlaceholder($sortby . '_checked', $checked);
$modx->setPlaceholder($checkbox1 . '_checked', $checked);
$modx->setPlaceholder($checkbox2 . '_checked', $checked);
<form action="[[~[[*id]]]]" method="POST"> <p id="radio"> <input type="radio" name="sort_method" id="radio4" value="itemno" onChange="this.form.submit();" /> <label for="radio4">Reset</label> <input type="radio" name="sort_method" [[+width_checked]] id="radio3" value="width" onChange="this.form.submit();" /> <label for="radio3">Sort by Width</label> <input type="radio" name="sort_method" [[+height_checked]] id="radio2" value="height" onChange="this.form.submit();" /> <label for="radio2">Sort by Height</label> <input type="radio" name="sort_method" [[+depth_checked]] id="radio1" value="depth" onChange="this.form.submit();" /> <label for="radio1">Sort by Depth</label> </p> <p> </p> <p id="check"> <input type="checkbox" name="check_cat1" [[+cat1_checked]] id="check1" value="cat1" onChange="this.form.submit();" /> <label for="check1">Category 1</label> <input type="checkbox" name="check_cat2" [[+cat2_checked]] id="check2" value="cat2" onChange="this.form.submit();" /> <label for="check2">Category 2</label> </p> <p> </p> </form>