where filter for Category sections
3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 3, 2013 (RSS)
By aev - November 29, 2013
Hi,
I get an error when trying to use the 'where' option for a Category section. How can I filter a Category section?
-aev-
By Dave - December 2, 2013
Hi aev,
There's no support for 'where' with getCategories() because any filtering would cause the hierarchy to not display correctly or have gaps in it.
Some alternatives would be to use the standard getRecords() instead and manually indent records based on $categoryRecord['depth'].
Or if you're displaying all the categories then move your where/filter code inside the foreach block and just skip records you don't want with something like:
<?php
<?php echo $categoryRecord['_listItemStart'] ?>
if (!contains('test', $categoryRecord['title'])) { // skip records without "test" in title
echo $categoryRecord['_listItemEnd']; // print closing </li> etc for this branch
continue;
}
?>
Alternatively, if you're just trying to display a specific branch, you could just load those with a direct query (just get all the records with a parentNum of 123, etc.
Let me know if one of those options will work for you.
interactivetools.com
By aev - December 3, 2013
Hi Dave,
I'm already using the "skip inside foreach" method, but sometimes depending on the task, it would be easier to do it with a where filter.
Thanks for explaining my options.
-aev-