Forum

Thread tagged as: Problem, Suggestions, Docs

Why can't I filter by catDepth?

My Perch installation is fully up to date.

I wanted to list top-level categories only, looking at the documentation and the existing templates, I tried:

<?php perch_categories(array(
  'set' => 'types',
  'template' => 'list_items.html',
  'filter' => 'catDepth',
  'match' => 'eq',
  'value' => '1'
)); ?>

The above does not display any categories, even though filtering for categories with depth 1 seems like the most logical way to me. Eventually, I hit upon a working solution:

<?php perch_categories(array(
  'set' => 'types',
  'template' => 'list_items.html',
  'filter' => 'catParentId',
  'match' => 'eq',
  'value' => ''
)); ?>

The trouble is, I can't find any reference in the docs about catParentId, I happened upon it in another forum answer. Why can't categories be filtered by their catDepth property?

Perhaps the documentation could be updated a bit, to clarify whatever is occurring in this case.

Evan Dobos

Evan Dobos 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

catDepth isn't a stored property - it's just added during templating for convenience. So you can't filter on it because it doesn't exist at that point.