2012-01-08 98 views
1

我有這樣的代碼在WordPress的`delete_post`動作中獲取帖子ID?

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

我怎樣才能得到這個職位的ID被刪除?

此外,如果在管理員中刪除多個帖子,這仍然可行嗎?

回答

5

掛鉤自動通過刪除帖子的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." 
    ;); 
}