如何以编程方式清空垃圾箱?


10

我需要在插件内创建一个“清空垃圾箱”按钮。我将如何使用PHP代码来做到这一点?

Answers:


9

您可以使用wp_delete_post

要获取所有具有“已删除邮件”状态的帖子,请执行以下操作:

$trash = get_posts('post_status=trash&numberposts=-1');

然后:

foreach($trash as $post)
  wp_delete_post($post->ID, $bypass_trash = true);

干杯! 有用!
西普里安(Ciprian)2012年

1

这对我不起作用。我必须执行以下操作:

$args = array(
'posts_per_page'   => -1,
'post_status'      => 'trash'
    );

$trash = get_posts($args);

foreach($trash as $post)
{
    wp_delete_post($post->ID, true);      
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.