在WordPress的`delete_post`动作中获取帖子ID?

时间:2012-01-08 09:06:12

标签: wordpress

我有这段代码

add_action( 'delete_post', 'my_delete_function' );
 function my_delete_function() { 
   global $wpdb;
   $wpdb->query("
    DELETE FROM wp_votes WHERE post=".$thePostID."
;);
 }

如何才能删除帖子的ID?

此外,如果在管理员中删除多个帖子,这仍然有用吗?

1 个答案:

答案 0 :(得分:6)

钩子会自动将删除的帖子ID传递给你的函数,所以你可以抓住它,查看文档here

add_action( 'delete_post', 'my_delete_function' );
function my_delete_function($postId) { 
   global $wpdb;
   $wpdb->query("
       DELETE FROM wp_votes WHERE post=".$postId."
   ;);
}