Forum

Thread tagged as: Question, Problem, Runway

collections filtering

I am trying to display items which belong to a collection and have been tagged with some categories.

So, i was thinking that this would work:

perch_collection('Products', [
     'template' => 'product_detail.html',
     'category' => perch_get('bracelets')),
]);

But sadly it doesen't. I believe the above works with perch_content_custom but it seems not to apply to perch_collection. What am I missing here? Any help would be appreciated

Spyros Perris

Spyros Perris 0 points

  • 6 years ago

the second closing parenthesis at the end of line 3 is not the problem

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Have you added debug to the page so you can see what is going on?

https://docs.grabaperch.com/docs/installing-perch/configuration/debug/

I am looking at the sql queries and I can't say what's going on. I tried to run them in Navicat and there are no errors but as it happens to my page, I get the full set of results not the subset.

Not sure if I should paste this here but maybe here is the problem

SELECT collectionID, collectionTemplate FROM perch2_collections WHERE collectionKey='Products'

SELECT idx.itemID FROM perch2_collection_index idx JOIN perch2_collection_revisions c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.collectionID=c.collectionID WHERE (idx.collectionID=1) AND ((idx.indexKey='_category' AND idx.indexValue LIKE '%'))

SELECT * FROM ( SELECT idx.itemID, ci.collectionID, ci.itemJSON, idx2.indexValue as sortval FROM perch2_collection_index idx JOIN perch2_collection_items ci ON idx.itemID=ci.itemID AND idx.itemRev=ci.itemRev AND idx.collectionID=ci.collectionID JOIN perch2_collection_revisions cr ON idx.itemID=cr.itemID AND idx.itemRev=cr.itemRev AND idx.collectionID=ci.collectionID JOIN perch2_collection_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE (idx.collectionID=1) AND idx.itemID IN (2, 1, 10, 15, 5, 9, 5, 9, 2, 1, 9, 10, 5, 9, 2) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is there a URL argument named bracelets that has a valid category path as its value?

There is a page with the url: https://dropsjewellery/en/jewellery/bracelets

And there is a category with a path: kind/bracelets/

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does your route look like?

The route for the above page is: en/jewellery/bracelets/[slug:product_slug]

But I have tried the same from another page such as https://dropsjewellery/en/jewellery/earrings that has no route.

In debuging It looks like when I change the request to say "rings" instead of "bracelets" nothing different is happening

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so you want something like

'category' => 'kind/' . perch_get('product_slug'),

Nothing different is happening.

Your solution is what's needed. But what stopped it from working was a problem in my custom set/category template.

I shall make this question in another thread to display the issue.

Thanks,