3

I'm trying to extend the ElementCriteriaModel using the guide here:

https://blog.tighten.co/craft-cms-building-complex-queries-by-extending-the-elementcriteriamodel

However I need to re-implement relatedTo keyword somehow. This is what I have so far but doesn't seem to work at all

    $criteria = craft()->elements->getCriteria(ElementType::Category);
    $criteria->slug = 'seasonal-event';
    $criteria->limit = 1;

    $category = $criteria->find();

    $this->criteria->relatedTo = array(
        'targetElement' => $category
    );

    return $this;
3

You're using $criteria, but attempting to set the relatedTo property on $this->criteria.

Assuming that's not the issue, have you tried using $criteria->setAttribute('relatedTo', ['targetElement' => $category])?

I've found setAttribute to be more reliable than the ElementCriteriaModel magic methods.

|improve this answer|||||

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.