WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got it! Buuuuut I had to edit 2 core files, yes! 2 core files :(

I know is not a cool plugin hack, but maybe a cool patch for WP, Im using 3.3.1 version.

Well, here is my little hack/contribution:


1 Comment:


2 Change:

$post = get_default_post_to_edit( $post_type, true );
$post_ID = $post->ID;


$post       = array();
$post_ID    = 0;


1 Change:

if ( isset( $_GET['post'] ) )
    $post_id = $post_ID = (int) $_GET['post'];
elseif ( isset( $_POST['post_ID'] ) )
    $post_id = $post_ID = (int) $_POST['post_ID'];
    $post_id = $post_ID = 0;


if ( isset( $_GET['post'] ) ) {

    $post_id = $post_ID = (int) $_GET['post'];

} elseif ( isset( $_POST['post_ID'] ) ) {

    if ( empty($_POST['post_ID']) ) {

        $post_type = wp_kses($_POST['post_type']);

        if( !post_type_exists($post_type) ) {

            $post_type = 'post';


        check_admin_referer('update-' . $post_type . '_' . (int) $_POST['post_ID']);

        global $user_ID;

        $defaults = array(
                            'post_status'   => 'draft',
                            'post_type'     => $post_type,
                            'post_author'   => (int) $user_ID,

        $postarr    = wp_parse_args( $_POST, $defaults );

        $post_ID    = wp_insert_post($postarr);

        $post_id    =  (int) $post_ID;



    } else {

        $post_id = $post_ID = (int) $_POST['post_ID'];


} else {

    $post_id = $post_ID = 0;


I am using JQuery to hide: add media stuff. Just only a unique ID entry is created in posts table (and not a bunch of useless Auto Draft entries related) and media stuff will be visible after user manually saves current post.

Rare behavior: When a user logins for the first time and is redirected to Dashboard, WP creates an Auto Draft entry in posts table, hmmm, crazy! Somebody knows why it works like that?

A better solution: perhaps not altering at any chance core files? It will be a great one! For example, with a checkbox in Settings to check or uncheck if we want the "autosave" feature or not (get_option). Somebody else wants to apply the patch?

Thanks in advance.

share|improve this question

Read the thread Disable/ Stop "auto-draft" posts on wp-hackers to understand why this is a very bad idea.

Let me quote the explanations from @Otto:

Auto-drafts exist because of the fact that multiple users can create new posts at the same time. If two people enter post-new at roughly the same moment, then have their first autosaves occur nearly simultaneously, then there is a race condition that can cause one of them to get back the wrong post ID, which will cause a post to be overwritten/lost when they then continue editing the post.

The auto-draft creates the post and gets the ID of the new post before the editing screen is displayed, thus preventing two simultaneous authors from accidentally having the same post ID in the data in their browser.


Auto-drafts are automatically deleted after 7 days of going unused. They're self-cleaning, basically. No need to worry about them.

They also go away when the first auto-save occurs while writing a new post.


You solve a non-existent problem in a way that makes further updates impossible. Stop wasting your valuable time, do something useful instead. :)

share|improve this answer
I thought MySQL can handle that, but is nice to learn about it from WP point of view. Cool to know about self-cleaning. Well Im going to do something useful as sleep a couple of hours. Thanks. But I still think a lot of IDs in post table is a kind of nasty solution, maybe Im 100% wrong :) – José Pablo Orozco Marín Mar 4 '12 at 6:29

Thanks for sharing this hack (it works!). I wish someone could make a plugin for it or WordPress would provides users option to disable.

Actually, every time I visit Dashboard home (while logged in, of course), an Auto Draft is created after 60 (?) seconds. Not 'rare' occurrence. Default WordPress behavior. Happens each time I visit Dashboard (NOT just after initial login redirect). I use a plugin that redirects me to another page (that I choose) after I login to WP - instead of being redirected to Dashboard. But this still means I can only view my Dashboard for less than 60 (?) seconds otherwise an Auto Draft will be created. Dumb Wordpress behaviour - wish there was a real solution.

share|improve this answer
Addendum: There's this quickie solution: plaxee.com/wordpress/how-to-disable-auto-draft But it looks like the author cut and paste his code incorrectly (and he hasn't responded to previous comments by readers). – Massa P Mar 29 '12 at 18:25
Yes, a plugin will be great if no core files were involved in my hack. Please let me know if you find an easier plugin or hack. Thanks in advance – José Pablo Orozco Marín Apr 17 '12 at 3:08

Your Answer


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.