<p>Depending on what you want to do with them you can request them using <a href="http://buildwithcraft.com/docs/templating/craft.entries" rel="nofollow">craft.entries</a> but you'll probably need to change the <strong>status</strong> to <strong>pending</strong>.</p>

<p>If this doesn't work you'll need to fetch them through a custom controller/service that goes in and fetches the <a href="http://buildwithcraft.com/docs/templating/entrymodel" rel="nofollow">entry model</a> and returns a list that fit you criteria.</p>

<p>Hope this helps.</p>

CC BY-SA 3.0
2014-12-02T23:25:29.737Z
2014-12-02T23:25:29.737Z
Adam McCombs
<p>Drafts store rows in the <code>craft_entrydrafts</code> table, relating to an entry, providing some context (author, date, notes), and serializing all the pending content into a data column. Craft normally gets drafts only as they relate to a specific entry, so you'll need to provide your own method of retrieving them all.</p>

<p>The EntryRevisionsService class has a method called getDraftsByEntryId(), which can be modified slightly to return all those draft records rather than ones limited specifically to a given entry:</p>

<pre><code>public function getEntryDrafts($localeId = null)
{
    if (!$localeId)
    {
        $localeId = craft()-&gt;i18n-&gt;getPrimarySiteLocale();
    }

    $drafts = array();

    $results = craft()-&gt;db-&gt;createCommand()
        -&gt;select('*')
        -&gt;from('entrydrafts')
        -&gt;where(array('locale = :locale'), array(':locale' =&gt; $localeId))
        -&gt;order('dateUpdated desc')
        -&gt;queryAll();

    foreach ($results as $result)
    {
        $result['data'] = JsonHelper::decode($result['data']);

        // Don't initialize the content
        unset($result['data']['fields']);

        $drafts[] = EntryDraftModel::populateModel($result);
    }

    return $drafts;
}
</code></pre>

<p>Each result will be an EntryDraftModel, so use the <code>draftId</code> parameter if you'd like to link directly to that draft as you'd normally see it in the control panel. In a Twig template, for example, that'd look like <code>{{ draft.cpEditUrl ~ "/drafts/" ~ draft.draftId }}</code>.</p>

CC BY-SA 3.0
2017-03-29T05:18:42.693Z
2017-03-29T05:32:51.137Z
2017-03-29T05:32:51.137Z
Matt Stein
<p>I'm building a widget where I want to list all unpublished drafts (made by users without access to publish live changes), but I can't figure out how to get them. </p>

<plugin-development><draft>
How can I get unpublished drafts in my plugin?
# How can I get unpublished drafts in my plugin?

(Asked by: username_0 on 2014-12-02)

I'm building a widget where I want to list all unpublished drafts (made by users without access to publish live changes), but I can't figure out how to get them.

**Tags:** plugin-development, draft


---

## 2 answers

### Answer by username_1 on 2014-12-02. Score: 3

Depending on what you want to do with them you can request them using [craft.entries](http://buildwithcraft.com/docs/templating/craft.entries) but you'll probably need to change the **status** to **pending**.

If this doesn't work you'll need to fetch them through a custom controller/service that goes in and fetches the [entry model](http://buildwithcraft.com/docs/templating/entrymodel) and returns a list that fit you criteria.

Hope this helps.


---

### Answer by username_2 on 2017-03-29. Score: 2

Drafts store rows in the craft_entrydrafts table, relating to an entry, providing some context (author, date, notes), and serializing all the pending content into a data column. Craft normally gets drafts only as they relate to a specific entry, so you'll need to provide your own method of retrieving them all.
The EntryRevisionsService class has a method called getDraftsByEntryId(), which can be modified slightly to return all those draft records rather than ones limited specifically to a given entry:
public function getEntryDrafts($localeId = null)
{
    if (!$localeId)
    {
        $localeId = craft()->i18n->getPrimarySiteLocale();
    }

    $drafts = array();

    $results = craft()->db->createCommand()
        ->select('*')
        ->from('entrydrafts')
        ->where(array('locale = :locale'), array(':locale' => $localeId))
        ->order('dateUpdated desc')
        ->queryAll();

    foreach ($results as $result)
    {
        $result['data'] = JsonHelper::decode($result['data']);

        // Don't initialize the content
        unset($result['data']['fields']);

        $drafts[] = EntryDraftModel::populateModel($result);
    }

    return $drafts;
}

Each result will be an EntryDraftModel, so use the draftId parameter if you'd like to link directly to that draft as you'd normally see it in the control panel. In a Twig template, for example, that'd look like {{ draft.cpEditUrl ~ "/drafts/" ~ draft.draftId }}.


---

