最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

posts - Why doesn't wp_delete_post allow trashing for custom types?

programmeradmin1浏览0评论

When you're trying to wp_delete_post a custom post type, it deletes it fully instead of moving it to trash as it is the normal behavior.

This happens because "force delete" is, by default false and it will only trash the post if it's of post / page type:

.9/src/wp-includes/post.php#L2467

Why is this happening and what are the dangers of re-writing this to handle every post type?

When you're trying to wp_delete_post a custom post type, it deletes it fully instead of moving it to trash as it is the normal behavior.

This happens because "force delete" is, by default false and it will only trash the post if it's of post / page type:

https://core.trac.wordpress/browser/tags/4.9/src/wp-includes/post.php#L2467

Why is this happening and what are the dangers of re-writing this to handle every post type?

Share Improve this question asked Aug 22, 2019 at 17:49 coolpastacoolpasta 9691 gold badge9 silver badges24 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Have you tried wp_trash_post?

This seems like the perfect fit for your purpose. It will only permanently delete posts if you have your trash disabled, or added define('EMPTY_TRASH_DAYS', 0); to your wp-config.php file.

发布评论

评论列表(0)

  1. 暂无评论