I'm outputting an element criteria model in a Craft 2 plugin of some entries in a channel. I noticed that when I fetch the entries the standard template way
{% set entries = craft.entries.section('channelHandle') %}
I am then able to do something like the following to refine the number of entries with the lightswitch turned on:
{% set refinedEntries = entries.customLightswitchField(1)|length %}
However, when I fetch my entries in my plugin, output them into the template, then try refining it as above:
// plugin
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'channelHandle';
$entries = $criteria->find();
return $entries;
// template
{% set entries = craft.myPlugin.fetch() %}
{% set refinedEntries = entries.customLightswitchField(1)|length %}
...I then get an Array to string conversion
PHP notice. I'm also not able to use things like .first()
like I normally would.
Is this expected behavior? Am I missing something when returning an element criteria model through a plugin?