<p>In your example, <code>checkbox</code> is an instance of <a href="http://buildwithcraft.com/classreference/fieldtypes/MultiOptionsFieldData" rel="nofollow">MultiOptionsFieldData</a>, which behaves like an array of all of the possible checkbox options.</p>

<p>It doesn't have a <code>__toString()</code> method on it, which is why you're getting the error.</p>

<p>I assume what you want to be doing is grouping by a selected checkbox, no?</p>

CC BY-SA 3.0
2014-11-21T15:33:37.390Z
I expected to be able to do the a similar thing with categories, but think I'm running into the same thing: ```{% set entries = craft.entries.section('media').find() %}
{% set entriesByCat = entries|group('mediaCategory') %}
``` Can we just not use `.group` like this?
Tim Kelty
CC BY-SA 3.0
2014-11-21T15:53:28.850Z
I meant `|group`, as in the filter :)
Tim Kelty
CC BY-SA 3.0
2014-11-21T16:28:58.117Z
Added a related recipe: http://craftcookbook.net/recipes/330
Tim Kelty
CC BY-SA 3.0
2014-11-21T16:29:24.857Z
It would be nice if `group` was aware of `Craft\ElementCriteriaModel`s, so you could do something like:```{% set entriesByCat = entries|group('myCategory.slug') %}```
Tim Kelty
CC BY-SA 3.0
2014-11-21T16:31:33.460Z
Though maybe that's a better case for a `groupCriteria` filter or something...ok I'll stop adding comments now.
Tim Kelty
CC BY-SA 3.0
2014-11-25T15:00:28.003Z
@paul, I just made a plugin to make this kind of grouping easier: https://github.com/timkelty/groupby-craft
Tim Kelty
CC BY-SA 3.0
2014-11-19T21:29:49.240Z
2014-11-19T21:29:49.240Z
Brad Bell
<p>What Brad says, plus an example of grouping by selected checkbox:</p>

<pre><code>{% set entries = craft.entries.section('my_entries') %}

{# get all checkbox options #}
{% set options = entries.first().checkbox.options %}

{% for option in options %}
    &lt;h2&gt;{{ option }}&lt;/h2&gt;
    &lt;ul&gt;
    {% for entry in entries if entry.checkbox.contains(option) %}
       &lt;li&gt;{{ entry.title }}&lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-11-19T21:33:19.283Z
2014-11-19T21:38:33.430Z
2014-11-19T21:38:33.430Z
Paul
<p>We're looking to output a list of entries and group them by their check box values. Here's what we've got so far:</p>

<pre><code>{% for checkbox, entries in craft.entries.section('my_entries').find() | group('checkbox') %}
   {{ checkbox }}
{% endfor %}
</code></pre>

<p>This currently returns "Object of class Craft\MultiOptionsFieldData could not be converted to string".</p>

<p>Any ideas? Is this even possible?</p>

<entries><group>
Is it possible to group entries by checkbox?
# Is it possible to group entries by checkbox?

(Asked by: username_0 on 2014-11-19)

We're looking to output a list of entries and group them by their check box values. Here's what we've got so far:
{% for checkbox, entries in craft.entries.section('my_entries').find() | group('checkbox') %}
   {{ checkbox }}
{% endfor %}

This currently returns "Object of class Craft\MultiOptionsFieldData could not be converted to string".
Any ideas? Is this even possible?

**Tags:** entries, group


---

## 2 answers

### Answer by username_3 on 2014-11-19. Score: 6 | Accepted answer

What Brad says, plus an example of grouping by selected checkbox:
{% set entries = craft.entries.section('my_entries') %}

{# get all checkbox options #}
{% set options = entries.first().checkbox.options %}

{% for option in options %}
    {{ option }}
    
    {% for entry in entries if entry.checkbox.contains(option) %}
       {{ entry.title }}
    {% endfor %}
    
{% endfor %}


---

### Answer by username_1 on 2014-11-19. Score: 1

In your example, `checkbox` is an instance of [MultiOptionsFieldData](http://buildwithcraft.com/classreference/fieldtypes/MultiOptionsFieldData), which behaves like an array of all of the possible checkbox options.

It doesn't have a `__toString()` method on it, which is why you're getting the error.

I assume what you want to be doing is grouping by a selected checkbox, no?

> **Comments:**
> **username_2**: I expected to be able to do the a similar thing with categories, but think I'm running into the same thing: ```{% set entries = craft.entries.section('media').find() %} {% set entriesByCat = entries|group('mediaCategory') %} ``` Can we just not use `.group` like this?  
> **username_2**: I meant `|group`, as in the filter :)  
> **username_2**: Added a related recipe: http://craftcookbook.net/recipes/330  
> **username_2**: It would be nice if `group` was aware of `Craft\ElementCriteriaModel`s, so you could do something like:```{% set entriesByCat = entries|group('myCategory.slug') %}```  
> **username_2**: Though maybe that's a better case for a `groupCriteria` filter or something...ok I'll stop adding comments now.  
> **username_2**: @paul, I just made a plugin to make this kind of grouping easier: https://github.com/timkelty/groupby-craft  

---

