<p>Fixed it for now by including a custom enum class in the base plugin file:
    

<pre><code>abstract class CustomElementType extends BaseEnum
{
    const Badges_Badge = 'Badges_Badge';
}
</code></pre>

<p>and then querying for the custom element in the plugin using <code>craft()-&gt;elements-&gt;getCriteria(CustomElementType::Badges_Badge);</code></p>

CC BY-SA 3.0
2017-04-06T11:36:09.050Z
2017-04-06T11:36:09.050Z
Matt Rose
<p><code>ElementType</code> is a native Craft class, so it doesn't know about the <code>Badges_Badge</code> const you're trying to access.</p>

<p>You can either do it by adding your own class that adds a <code>Badges_Badge</code> const, <a href="https://craftcms.stackexchange.com/a/19830/57">like you discovered</a>, or simply use:</p>

<pre><code>craft()-&gt;elements-&gt;getCriteria('Badges_Badge');
</code></pre>

CC BY-SA 3.0
2017-04-06T17:01:25.117Z
2017-04-06T17:01:25.117Z
2017-04-13T12:51:00.200Z
Brad Bell
<p>I've setup a custom element type for badges for a system I'm building, but I've run into some trouble trying to query for badges using <code>craft()-&gt;elements-&gt;getCriteria(ElementType::Badges_Badge);</code>, however I'm getting an error saying 'Undefined class constant 'Badges_Badge', but when I loop through all element types using getAllElementTypes() I see an entry for 'Badges_Badges', and I'm able to add and edit badges in the cms. </p>

<p>Is it impossible to query for custom elements using getCriteria, or am I missing something more fundamental?</p>

<elementcriteriamodel><elementtype><custom><element>
Using getCriteria with a custom element type
# Using getCriteria with a custom element type

(Asked by: username_0 on 2017-04-06)

I've setup a custom element type for badges for a system I'm building, but I've run into some trouble trying to query for badges using `craft()->elements->getCriteria(ElementType::Badges_Badge);`, however I'm getting an error saying 'Undefined class constant 'Badges\_Badge', but when I loop through all element types using getAllElementTypes() I see an entry for 'Badges\_Badges', and I'm able to add and edit badges in the cms.

Is it impossible to query for custom elements using getCriteria, or am I missing something more fundamental?

**Tags:** elementcriteriamodel, elementtype, custom, element

---

## 2 answers

### Answer by username_0 on 2017-04-06. Score: 1

Fixed it for now by including a custom enum class in the base plugin file:
    

abstract class CustomElementType extends BaseEnum
{
    const Badges_Badge = 'Badges_Badge';
}

and then querying for the custom element in the plugin using craft()->elements->getCriteria(CustomElementType::Badges_Badge);


---

### Answer by username_1 on 2017-04-06. Score: 0

ElementType is a native Craft class, so it doesn't know about the Badges_Badge const you're trying to access.
You can either do it by adding your own class that adds a Badges_Badge const, like you discovered, or simply use:
craft()->elements->getCriteria('Badges_Badge');


---

