2

Within a plugin I am fetching existing entries using the CriteriaModel class as documented here http://buildwithcraft.com/docs/plugins/working-with-elements#fetching-elements, specifically like this:

$existing = craft()->elements->getCriteria($this->entry->elementType)->first(array(
    'someHandle' => 'someValue'
))

However I am finding this only returns a result if an ENABLED entry is found. I can see that I can search for ONE particular enabled state as follows:

$existing = craft()->elements->getCriteria($this->entry->elementType)->first(array(
    'someHandle' => 'someValue', 
    'enabled' => 1
))

Or...

$existing = craft()->elements->getCriteria($this->entry->elementType)->first(array(
    'someHandle' => 'someValue', 
    'enabled' => 0
))

But how can I search for ALL entries regardless of the enabled state?

And also, what is the difference between the status and enabled properties on the model? I can see constants for ENABLED, DISABLED and ARCHIVED. I'm not clear on how this differs from the boolean value that the enabled property has.

1 Answer 1

3

I haven't tried this in php, but on the 'template' side there is an attribute called 'status' which you might try. I assume it would work in php as well.

$existing = craft()->elements->getCriteria($this->entry->elementType)->first(array(
    'someHandle' => 'someValue', 
    'status' => null
));

Default is 'live'; other values would be 'live', 'pending', 'expired', 'disabled', and null. Here's the docs for craft.entries.status. Let us know if it works.

4
  • What Douglas said. There’s actually no enabled criteria parameter; only status. Setting it to null will prevent the elements’ statuses from getting factored into the query. Dec 31, 2014 at 19:30
  • Thanks guys. A follow up though - I can see I can use null to get ALL, but if I only want live and pending, how do I do that? In PHP.
    – Russ Back
    Jan 12, 2015 at 21:57
  • Again, on the backend I'm not 100% sure, but I think that you can simply place all the options in an array like so: 'status' => ['live', 'pending'] or you might also try 'status' => ['and', 'live', 'pending'] or perhaps 'status' => array('and', 'live', 'pending'). Jan 12, 2015 at 22:31
  • If this answer is any indication it should be the latter 'status' => array('and', 'live', 'pending') Jan 12, 2015 at 22:51

Your Answer

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

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