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
版权声明:本文标题:Exclude auto drafts from listing of custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741457916a2379863.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论