I have a custom element type with 2 custom fields, 'name' and 'email'. I can't seem to get the index search working for this element type. I defined defineSearchableAttributes and returned an array with these 2 attributes. Searching on the title field works though.

namespace Craft;

class Newsletter_SubscriptionElementType extends BaseElementType {

public function getName() {
    return Craft::t('Subscriptions');

public function hasContent() {
    return true;

public function hasTitles() {
    return true;

public function populateElementModel($row) {
    return Newsletter_SubscriptionModel::populateModel($row);

public function defineCriteriaAttributes() {
    return array(
        'name'      => AttributeType::String,
        'email'     => AttributeType::Email

public function defineSearchableAttributes() {
    return array('name','email');

public function defineTableAttributes() {
    $attributes = array(
        'title'         => Craft::t('Title'),
        'name'          => Craft::t('Name'),
        'email'         => Craft::t('Email'),
        'dateCreated'   => Craft::t('Date Created')

    return $attributes;

public function getTableAttributeHtml(BaseElementModel $element, $attribute) {
    return parent::getTableAttributeHtml($element, $attribute);

public function getSources($context = null) {
    $sources = array(
        '*' => array(
            'label'    => Craft::t('All subscriptions'),

    return $sources;

public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) {
        ->addSelect('newsletter_subscriptions.name, newsletter_subscriptions.email')
        ->join('newsletter_subscriptions newsletter_subscriptions', 'newsletter_subscriptions.id = elements.id');
  • That method only comes into play when you're saving your custom element... is that how you're testing?
    – Brad Bell
    Commented Jun 12, 2017 at 23:30
  • You mean that a new entry has to be posted after I defined that method before craft can search that entry? Commented Jun 13, 2017 at 7:52
  • Correct... Craft will extract the search keywords for an element after it is saved. If you've added that method after you have existing elements, they'll need to be resaved.
    – Brad Bell
    Commented Jun 13, 2017 at 21:08

1 Answer 1


Craft will only extract the search keywords for an element during the element saving process.

If you have existing custom elements already saved, then you go in and add the defineSearchableAttributes() to your element type, you'll need to re-save the existing elements in order for their search keywords to be indexed.

Or now that I think about it... the easier way would probably be to just run the "Update Search Indexes" tool in the Control Panel under Settings->Tools. It will do the same thing for you.

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.