扩展@Brian Fegter的答案Above 您可以使用下面的插件批量删除帖子。它创建了一个WP管理页面,其中包含一个文本区域,用于删除页面/帖子的ID。
<?php
/*
Plugin Name: Delete Posts By ID
Description: Delete posts and pages by id
Version: 0.1
Author: WPSE
License: GPL2
*/
add_action( \'admin_menu\', \'deletePostsMenu\' );
function deletePostsMenu() {
add_menu_page(
\'Delete Posts\',
\'Delete Posts\',
\'manage_options\',
\'delete-posts/delete-posts-admin-page.php\',
\'delete_posts_admin_page\',
\'dashicons-trash\',
6
);
}
function delete_posts_admin_page() {
?>
<div class="wrap">
<h2>Delete Posts By ID</h2>
<p>Add post/page ids separated by a line break</p>
<form action="" method="post">
<label for="deletePostsByID"></label>
<textarea name="deletePostsByID" id="ids" cols="30" rows="10"></textarea>
<input type="submit">
</form>
</div>
<?php
if (isset($_POST[\'deletePostsByID\'])) {
delete_posts($_POST[\'deletePostsByID\']);
return;
}
}
//add_action(\'admin_init\', \'manually_delete_post\', 0);
function delete_posts($submittedIDs){
if(!is_user_logged_in())
return;
if(!current_user_can(\'manage_options\'))
return;
/* // Strip whitespace
$stripped = str_replace(\' \', \'\', $submittedIDs);*/
// Set to array
$idsArray = explode("\\r\\n",$submittedIDs);
echo \'<ol>\';
// Delete posts by id
foreach ($idsArray as $id){
$delete = wp_delete_post($id, false); //True force deletes the post and doesn\'t send it to the Trash
if($delete)
echo "<li>Post $id deleted successfully!</li>";
else
echo "<li>Post $id was not deleted.</li>";
}
echo \'</ol>\';
exit;
}