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?

2 Answers 2


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);


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:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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