admin管理员组

文章数量:1415421

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.

本文标签: postsWhy doesn39t wpdeletepost allow trashing for custom types