I'm trying to get the drafts for the entry on the front end to populate my plugin on the sidebar but cannot get the drafts returned with this code in a Twig template.

entry is an EntryModel here.

The entry ID is {{entry.id}} 

{% set drafts = craft.entryRevisions.getDraftsByEntryId(entry.id) %}

{{ dump(drafts) }}

drafts is an array of 0 elements

Even trying it in a PHP plugin class and hard-coding the entry ID like

$drafts = craft()->entryRevisions->getDraftsByEntryId(995);

$drafts is empty.

Everywhere I've looked says to do like the above; however, this doesn't return any drafts that belong to the entry as expected.

In the dropdown by the entry name, it has the 2 Drafts' names and when clicking them it takes me to the draft, so it seems like the drafts are correctly mapped to this entry.

What am I missing?


Specify the locale when getting the drafts, or else it will fetch drafts for the default locale. In my case, there was only drafts for a particular locale but not the default.

{% set drafts = craft.entryRevisions.getDraftsByEntryId(entry.id, 'localeId') %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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