1

I have a blog section with multi select categories. I want to filter all the blogs based on that multi select categories in the website. When I tried

 .search('category:ui-ux OR category:web-designs')

the result blogs are not accurate.

Category is a multi select field. So multiple category may assigned to one blog. I will list all these categories in my front end and need to filter blogs based on that.

How I will do this search?

  • Is the field handle you are trying to search category? – Oli May 19 at 7:30
  • yes , the field handle of the multi select field that I added from admin is 'category'. – Rakhi Vijayan May 19 at 9:54
1

For filtering entries based on relationships (categories/assets/users/tags/other entries), you need to use the relatedTo parameter, not the search parameter.

Here's an example: Filter based Search Form

| improve this answer | |
  • Thank you. Let me check – Rakhi Vijayan May 19 at 11:54
  • can you please advice, what is this .group('knowledge') in query? – Rakhi Vijayan May 19 at 12:00
  • That's simply outputting categories from a category group called 'knowledge'. It's not relevant to your question - you just need to use the relatedTo parameter instead of the search parameter as detailed in that question. – James Smith May 19 at 13:02
  • Thank you. {% paginate craft.entries.section('blog').relatedTo('category:ui-ux OR category:healthcare').orderBy('postDate desc').limit(10) as pageInfo, entryTemplates %} . This not works for me, getting empty results. – Rakhi Vijayan May 20 at 11:37
  • To use the relatedTo parameter you need to pass it either the category element(s), or the id(s) of the category/categories. See the docs: docs.craftcms.com/v3/relations.html#the-relatedto-parameter – James Smith May 20 at 15:04

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.