如何立即永久删除帖子/页面?

时间:2014-06-03 作者:leymannx

出于开发目的,我需要不断用虚拟内容填充和取消填充Wordpress实例。分两步删除所有内容很烦人,所以我想知道是否有办法在删除帖子时减少垃圾。请帮忙。

3 个回复
最合适的回答,由SO网友:Matt 整理而成

考虑到这个网站是WordPress开发的,我假设您想知道如何(强制)以编程方式删除帖子。

wp_delete_post(257, true); // `true` indicated you would like to force delete (skip trash)

More on wp_delete_post() function

SO网友:NETCreator Hosting - WebDesign

您可以设置自动清空垃圾箱的时间间隔:

在wp配置中。php输入:

define(\'EMPTY_TRASH_DAYS\', 1 ); //Integer is the amount of days
EDIT: 要禁用垃圾箱,请将天数设置为零(http://codex.wordpress.org/Editing_wp-config.php)

希望有帮助!

SO网友:leymannx

使用WP-CLI,结合wp post listwp post delete 使用--force 跳过垃圾箱的选项如下:

# Delete all posts skipping trash
$ wp post delete $(wp post list --post_type=\'post\' --format=ids) --force
其他示例:

# Delete post skipping trash
$ wp post delete 123 --force
Success: Deleted post 123.

# Delete all pages
$ wp post delete $(wp post list --post_type=\'page\' --format=ids)
Success: Trashed post 1164.
Success: Trashed post 1186.

# Delete all posts in the trash
$ wp post delete $(wp post list --post_status=trash --format=ids)
Success: Deleted post 1268.
Success: Deleted post 1294.

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register