How do you get Criteria to work ????
Created 7 years ago by kiltedup

I am trying in vain to get some custom Criteria to work - in vain as in 'failing miserably' !!!

The Streams plugin documentation states "Pro Tip: The entry criteria is extendable! To learn how to add your own functionality to queries refer to the criteria documentation." but I can't locate that.

I have been messing around trying a few things.

So I have the following test code while playing around :

class PlatformCriteria extends EntryCriteria
{
    public function descending()
    {
        $this->query->orderBy('created_at', 'DESC');
        return $this;
    }

    public function ascending()
    {
        $this->query->orderBy('created_at', 'ASC');
        return $this;
    }
}

And then in a twig I do this :

{% set platforms = entries('funding', 'platforms').ascending().get() %}
{% for platform in platforms %}
    <p>{{ platform.id }} : {{ platform.created_at }}</p>
{% endfor %}

{% set platforms = entries('funding', 'platforms').descending().get() %}
{% for platform in platforms %}
    <p>{{ platform.id }} : {{ platform.created_at }}</p>
{% endfor %}

Output from both is identical so the criteria is doing nothing.

Any tips on a) why the above would not work or b) what magic witchcraft is needed to make it work 😄

Cheers

Dave

ryanthompson  —  7 years ago

Have you bound your model to the generated one? This is something that's automated as of recently but is necessary for helping the system locate your model with the criteria next to it.

kiltedup  —  7 years ago

Thanks for reply. Yup - have bound the model. It's all very odd - got the criteria working in other streams but just not this one. Confused !!

ryanthompson  —  7 years ago

If you dd the entries('funding', 'platforms') what do you get?