Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I have a built a little plugin that calls the Twitter API to add new Tweets from a user timeline as entries, so that I can return them in an ElementCriteriaModel request to be integrated with content from other Sections.

I am trying to find out the largest tweet ID currently in the Craft system, where tweet IDs are stored as a text field against an entry, so that the next call to the Twitter API can set the sinceId field to only return tweets newer than the latest one currently stored in Craft.

I am doing this by doing an ElementCriteriaModel call, setting the order parameter to 'tweetId desc' and then attempting to find the first() entry, to retrieve the tweetId from that entry.

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'tweet';
$criteria->order = array('tweetId desc');
$criteria->status = array(BaseElementModel::ENABLED, BaseElementModel::DISABLED, BaseElementModel::ARCHIVED);

$latestTweet = $criteria->first();
$latestTweetId = $latestTweet->tweetID;

However, when I do this, the ordering of the Tweets seems to be affected by the status of the entry. It seems to be returning the tweet with the largest ID with status DISABLED, rather than the largest ID across all stored tweets.

Is this behaviour correct, or is there a better way to do this? I do need to be able to set certain tweets to disabled, if I don't want them shown on the front-end of the site.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Your statuses are incorrect. They would be correct for many elements, but the Entry Element overwrites them to the following:

EntryModel::LIVE
EntryModel::PENDING
EntryModel::EXPIRED
BaseElementModel::DISABLED
share|improve this answer
    
That's perfect, thank you! –  Alex H Jun 27 at 11:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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