1

I'm looking for a way to query all categories that have at least one relation. I'm not looking for the relatedTo() parameter, which would give me categories related to something specific.

Basically, if we talk in Wordpress terms, I'm looking for hideEmpty = true.

Is there anything like that in Craft?

Something like: craft.categories.group('products').hasRelated()
1

Add this to your chain...

.yourCategoryField(':notempty:')

It's not very well documented, but you can see it described in this old SE thread. In the docs, it's mentioned very briefly here.

  • Hi Lindsey, Thanks for your answer. Unfortunately, that would give me all entries that have a Category associated to it. I want it the other way around. I need all Categories that were assigned at least once somewhere. – Eric Chantigny Oct 23 '18 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.