Forum

Thread tagged as: Question

Filter Multiple Categories

Sorry, new part to this question...

I have multiple category sets. Is there a succinct way to search all of those even if they are not all set?

perch_content_custom('Rings', array(
    'category' => array('collection/' . perch_get('collection'), 'style/' . perch_get('style'), 'type/' . perch_get('type')),
    'template' => 'rings.html',
    'count' => 24,
    'paginate' => true,
));

// This will work if all $_GET variables are set.
// It does not seem to work if one is not set.
Nicholas Nelson

Nicholas Nelson 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

$categories = array();

if (perch_get('collection')) {
    $categories[] = 'collection/' . perch_get('collection');
}

if (perch_get('style')) {
    $categories[] = 'style/' . perch_get('style');
}

if (perch_get('type')) {
    $categories[] = 'type/' . perch_get('type');
}

perch_content_custom('Rings', array(
    'category' => $categories,
    'template' => 'rings.html',
    'count' => 24,
    'paginate' => true,
));

Cool, that was my next move if there wasn't a perch way!

I'm really sorry, I have another issue... The resulting perch_content_custom call seems to be calling, say, all men's rings and all classic rings. Not all men's rings that are also classic rings.

Does that make sense?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Set category-match to all

Ugh, I'm still having trouble...

here is the code:

$categories = array();

if (perch_get('collection')) { $categories[] = 'collection/' . perch_get('collection'); }
if (perch_get('style')) { $categories[] = 'style/' . perch_get('style'); }
if (perch_get('type')) { $categories[] = 'type/' . perch_get('type'); }

perch_content_custom('Rings', array(
    'category' => $categories,
    'category-match' => 'all',
    'template' => 'rings.html',
    'count' => 24,
    'paginate' => true,
));

When I have only one category set, it works properly.

When I have two categories set, I get no results.

When I have all three set, I get either 0 or 1 result which is not the number of results I should get.

I tried deleting and reseting my categories in the admin just in case. No change to my results. Any thoughts?

Additionally, is it possible to "filter" content by category on the admin side? I know this is done with the Perch Blog and Assets, but can it be done with Perch Content?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you try with Perch 2.7.3? I just fixed a bug which may happen to impact this.

GREAT! I think that worked :)

Any word on filtering perch content on the admin side by category such as the blog and assets?

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's not currently possible.