wp_delete_post()通过id删除文章

目录

描述

译文

根据文章编号删除文章

原文

Removes or trashes a post, attachment, or page.

When the post and page goes, everything that is tied to it is deleted also. This includes comments, post meta fields, and relationships between the post and taxonomy terms.

wp_delete_post() 描述

用法

 <?php wp_delete_post$postid$force_delete ); ?>

wp_delete_post() 用法

参数

$postid

(integer) (可选) Post ID.

默认值: 0

$force_delete

(bool) (可选) Whether to bypass trash and force deletion (added in WordPress 2.9).

默认值: false

wp_delete_post() 参数

返回值

(mixed) 

The post object (if it was deleted or moved to the trash successfully) or false (failure). If the post was moved to to the trash, $post represents its new state; if it was deleted, $post represents its state before deletion.

wp_delete_post() 返回值

示例

Delete Post

Deleting WP default post "Hello World" which ID is '1'.


 <?php wp_delete_post(1); ?> 

wp_delete_post() 示例

注意

  • wp_delete_post() automatically reverts to wp_trash_post() if $force_delete is false, the post_type of $postid is page or post, $postid is not already in the trash and if that trash feature enabled (which it it is by default).
  • 使用到: do_action() on 'delete_post' before deletion unless post type is 'attachment'.
  • 使用到: do_action() on 'deleted_post' after deletion unless post type is attachment.
  • 使用到: wp_delete_attachment() if post type is attachment.
  • 使用到 global $wpdb: (object) wpdb
  • 使用到 global $wp_rewrite: (object) WP_Rewrite

wp_delete_post() 注意

历史

添加于 版本: 1.0.0

wp_delete_post() 历史

源文件

wp_delete_post() 函数的代码位于 wp-includes/post.php.

wp_delete_post() 源文件

相关