Forum

Thread tagged as: Question, Runway

Create a user-filterable list using Categories assigned to an item in a Collecti...

Is it possible to create a user-filterable list using Categories assigned to an item in a Collection?

I've got a Collection setup for documents, and a Category Set called Manufacturers, with each manufacturer as a Category. Each item in the collection has a manufacturer assigned to it.

Simply, I want a user to go to the documents page, select 'Bloggs' as the manufacturer and only be shown documents of that manufacturer.

I've got the form setup and select options pre-populated with manufacturers - but I've got stuck on the value that it should be filtered by.

If I do a <perch:showall/> on my list of documents, the category ID is shown as an array:

Array
(
[0] => 4
)

Is there a way to match the perch_get('some_value_here') with the category ID array?

Darren Neasham

Darren Neasham 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use perch_categories() to get a list of categories from a set - is that not what you need here?

No, but that made me realise what I'd done. I was following the example 'How do I create a user-filterable list?' in the Articles and Solutions section.

In effect I was trying:

perch_collection('Documents', array(
  'template' => 'documents.html',
  'filter' => 'category',
  'match'  => 'eq',
  'value'  => perch_get('category'),
));

When it should have been:

perch_collection('Documents', array(
  'category' => perch_get('category'),
  'template' => 'documents.html',
));

I then followed the example in this post https://forum.grabaperch.com/forum/11-09-2014-filter-multiple-categories to filter multiple categories - and all now works as intended.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Great!