It seems like this should be a simple thing, but it's evading me... I have a checkbox field in my entry named "articles_categories". Just to clarify, these are not actual categories -- they are checkboxes and I cannot modify them at this point.

I want to use the option value of the checkbox as an exact search parameter. I'm using pagination, so it needs to pass through paginate. This is what I have:

{% set topic = craft.request.getQuery('topic') %}

{% paginate craft.entries.section('blogArticles').limit(10).search(topic) as pageInfo, pageEntries %}

The option values are being passed as the topic parameter. For example, '?topic=healthcare', or '?topic=food-fitness'. I'm getting a different set of results from each query, however, I don't believe that this is set up to return an exact match on the value passed through the search function.

I need only the articles that have an exact match in that field.


The value is stored as a serialized array in your database, you would need to filter for the string "["healthcare","food-fitness"]"

Since your query parameter is an array you just need to prepend an and parameter to it so it looks like

articles_categories(['and',  '*healthcare*', '*food-fitness*'])

If you have only one parameter and want an exact match you need to search for the exact string

  • So, I pass it like this: {% paginate craft.entries.section('blogArticles').limit(10).search(articles_categories(['and', 'healthcare', 'food-fitness'])) as pageInfo, pageEntries %} ? This doesn't work. Perhaps you can expand your answer to include my example? Also, I'm only passing one search parameter in my entry query and I want to match exact on that one parameter only. Aug 26 '18 at 20:17
  • I added an example that will fit your needs. The search parameter is not what you want. You need to set the articles_categories property Aug 27 '18 at 5:09
  • What does my answer has to do with categories and why should you need to change those? My answer is completely compatible with pagination Aug 27 '18 at 14:14
  • You're right, so I deleted my comment. What I really want to do is give you credit for this answer, but I'm taking the code you're providing me and putting it in place, and it's still not returning. Perhaps if you expanded your answer to not just include small snippets, but instead include a full example? If another user were to see your answer, they would not be able to use it because it's very limited. Aug 27 '18 at 14:31
  • This place is not meant for "copy & paste" code. It's for learning purpose and there is no real reason to include the entire unnecessary parameters to the query. So if someone later wants to get to know how to fetch elements based on checkbox values he/she will only see the required information. The paginate function requires a parameter of type ElementQuery you only need to change the property of your field handle to the exact value in your DB, that's it. {% paginate craft.entries.section('blogArticles').limit(10).articles_categories('["healthcare"]') as pageEntries %} Aug 27 '18 at 14:55

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.