3

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.

0

1 Answer 1

6

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
0

Your Answer

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

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