How can i use &where
filtering in my getImageList
call to output only results for forms whose MIGX_formname
start with a certain word?
This here doesn’t work:
&where=`{"MIGX_formname:LIKE":"Car_%"}`
&where=`{"MIGX_formname:LIKE":"Flower_%"}`
You can’t use normal SQL filtering, because here you are filtering the items of a JSON array and not rows in a database.
Take a look at the function filterItems to see what options are available:
public function debug($key, $value, $reset = false) {
$debug[$key] = $value;
$chunk = $this->modx->getObject('modChunk', array('name' => 'debug'));
$oldContent = $reset ? '' : $chunk->getContent();
$chunk->setContent($oldContent . print_r($debug, 1));
$chunk->save();
}
function filterItems($where, $items) {
$tempitems = array();
foreach ($items as $item) {
$include = true;
foreach ($where as $key => $operand) {
$key = explode(':', $key);
$field = $key[0];
$then = $include;
$else = false;
$subject = $item[$field];
It probably works if you use contains
.
Another option is to create a custom snippet (based on the getImageList snippet) where you code the filtering yourself based on your exact needs.
1 Like
Thanks @halftrainedharry – contains
works:
&where=`{"MIGX_formname:contains":"Car_"}`
system
Closed
May 21, 2023, 6:22pm
4
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.