get_posts()
可以接收描述要操作哪个post状态的参数。我会这样说:
function remove_all_kba_data(){
//remove articles
$articles = get_posts(
[
\'post_type\' => \'kb_kba\',
\'posts_per_page\' => -1,
\'post_status\' => [ \'published\', \'draft\' ]
]
);
foreach( $articles as $article ) {
//delete post, bypass trash
wp_delete_post( $article->ID, true);
}
}