問題描述

我需要在我的外掛中建立一個”Empty Trash” 按鈕。我如何使用 PHP 程式碼?

最佳解決方案

您可以使用 wp_delete_post

要獲得”trash” 狀態的所有帖子:

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

然後:

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

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。