admin管理员组

文章数量:1289911

I have a custom post type with custom post statuses. So to list my posts in the admin area that lists all my posts, I do the following:

add_action('pre_get_posts', function ($query) {
    MyPostClass::setTypes($query);
}, 10, 1);

and

public static function setTypes($query){
    if (!isset($_GET['post_status'])) {
        $query->set('post_status', array('new', 'answered'));
    }
}

If I don't do this, nothing ist listend. But although I only want to show the posts with the given status, it always lists all the posts with the status "auto-draft" too. I've tried everything that came to my mind, but I didn't manage to get rid of these entries. Can someone please help me out?

My first idea was to forbid auto saves, but the file "post-new.php" always creates a draft when called. So this is not an option for me.


EDIT

I've digged a little further into the file class-wp-query.php and I'm currenlty doing the following to resolve my problem. But could it have any unwanted side-effects?

add_action('posts_request_ids', 'removeDrafts');

function removeDrafts($request){
    return str_replace('WHERE 1=1  AND wp_posts.post_type = \''.MY_POST_TYPE.'\'  ORDER',
        'WHERE 1=1  AND wp_posts.post_type = \''.MY_POST_TYPE.
                '\' AND wp_posts.post_status != \'auto-draft\' ORDER',
        $request);
}

本文标签: Exclude auto drafts from listing of custom post type