Post Auto Draft Issue

I’ve made custom post type without title and editor and I use custom taxonomies, custom fields and attachments to form a post. My title is generated from custom taxonomies and custom fields (or “ID #” if nothing else is set). Here’s title code (could use some polishing probably):

function custom_post_type_title ( $post_id ) {
    global $wpdb;
    if ( get_post_type( $post_id ) == 'cars' ) {
        $autos = wp_get_object_terms($post_id, 'brand');
            $brand= '';
            $model="";
                foreach ( $autos as $auto ) {
                    if ( $auto->parent == 0) {
                        $brand = ' '.$auto->name;
                    } else {
                        $model .= ' '.$auto->name;
                    }
                }
        $engine = get_post_meta($post_id, 'Engine', true);
        if ($engine != '') { $engine=", ".$engine.'l'; }
        $title = $brand.$model.$engine;
        if ($title == '') { $title="ID ".$post_id; }
        $slug = sanitize_title('id-'.$post_id.$brand.$model.$engine);
        $where = array( 'ID' => $post_id );
        $wpdb->update( $wpdb->posts, array( 'post_title' => $title, 'post_name' => $slug), $where );
    }
}

add_action('init', 'cars_save_post');
function cars_save_post($post_id) {
        if ( ! defined( 'DOING_AUTOSAVE' ) && ! DOING_AUTOSAVE ) return;
        add_action('save_post', 'custom_post_type_title', 100);
        add_action('publish_post', 'custom_post_type_title', 100);
}

Problem is, if I attach an image and navigate away from the post, post will be saved, but won’t apear as draft in my post list. The only way (that I know of) I can reach it – thru media’s “attached to” link.

Not sure if it’s a bug or what, but I would like to see those posts in my Manage Posts list. Any solutions?

EDIT:

Maybe I wasn’t clear enough. Just try this scenario:

  • Add New Post (regular post will do);
  • Upload an Image to it;
  • Keep everything else empty;
  • Do not save the post;
  • Leave the page;

Now if you’ll check your Posts page, you won’t find an “Auto Draft” in it.
But if you’ll check your Media page, image you uploaded just now, will be attached to “Auto Draft”, which you can access from there. Even if you delete that image, that post will stay.

I just want to keep my server clean, so if Author made a mistake and forgot to save his post, he should have an easy access to that post via Posts Page.

So my question was, is this a bug and how can I fix it (display “Auto Drafts” in authors Posts page)?

1 Answer
1

You probably need to modify the columns displayed in your Custom Post posts list, so that the list isn’t dependent solely on Post Title.

I have a similar situation, with a Custom Post Type that consists solely of a “featured image” (and a “link” custom metabox). I modified the Post list to output the image, which linked to the edit-post page.

You may need to do something similar.

Leave a Comment