正如函数名所示,wp_trash_post()
仅垃圾帖子。如果您想将帖子完全删除,则可以使用wp_delete_post( int $postid, bool $force_delete = false )
相反
https://developer.wordpress.org/reference/functions/wp_delete_post/
当文章和页面被永久删除时,与之相关的所有内容也会被删除。这包括评论、帖子元字段和与帖子相关的术语。
除非禁用垃圾箱、项目已在垃圾箱中或$force\\u delete为true,否则帖子或页面将移至垃圾箱而不是永久删除。
<小时>
EDIT 14.11.2019
也许WP只是发疯了,因为你正在使用
wp_trash_post
同样的
$post_id
在
while
环也许您可以测试以下函数之一,这是我根据您的代码编写的,具体取决于您是要删除单个还是所有匹配的帖子。
function run_every_five_minutes_delete_one_matched_post() {
global $post;
if ( empty($post->ID) ) {
return;
}
$wp_query = new WP_Query(
array(
\'p\' => $post->ID, // query only for this particular post
\'date_query\' => array(
\'after\' => \'2 hours ago\',
\'inclusive\' => true
),
\'no_found_rows\' => true,
\'update_post_meta_cache\' => false,
\'update_post_term_cache\' => false,
\'fields\' => \'ids\' // no need to query all of the post data
)
);
if ($wp_query->posts) {
wp_delete_post($post->ID, true); // second parameter true bypasses trash and force deletes the post
}
}
function run_every_five_minutes_delete_all_matched_posts() {
$wp_query = new WP_Query(
array(
\'cat\' => array(1),
\'posts_per_page\' => -1,
\'date_query\' => array(
\'after\' => \'2 hours ago\',
\'inclusive\' => true
),
\'no_found_rows\' => true,
\'update_post_meta_cache\' => false,
\'update_post_term_cache\' => false,
\'fields\' => \'ids\'
)
);
if ($wp_query->posts) {
array_walk($wp_query->posts, function($post_id){
wp_delete_post($post_id, true); // second parameter true bypasses trash and force deletes the post
});
}
}