我有这段代码
add_action( 'delete_post', 'my_delete_function' );
function my_delete_function() {
global $wpdb;
$wpdb->query("
DELETE FROM wp_votes WHERE post=".$thePostID."
;);
}
如何才能删除帖子的ID?
此外,如果在管理员中删除多个帖子,这仍然有用吗?
答案 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."
;);
}