向函数中添加一个参数,该参数将传递被删除的当前帖子的ID。
add_action( \'delete_post\', \'my_delete_function\' );
function my_delete_function( $post_id /* <- ID of post being deleted */ )
{
global $wpdb;
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}_votes WHERE post = %d", $post_id ) );
}
使用任何外部变量(如@Asko的答案中的全局变量)都会消除以下任何保证
actually being deleted 是您在功能中正在处理的内容-它可能会完全失败,甚至会删除错误帖子的数据!