我在插件中製作一個函數,當帖子移動到垃圾箱時,函數將刪除數據庫行。但是,我無法使用get_posts()
獲得post_id。如何獲取所有post_id刪除帖子? Wordpress
這裏是我的代碼:
function delete_condition($post)
{
global $wpdb;
$allposts = get_posts(array(
'numberposts' => -1,
'category' => 0, 'orderby' => 'date',
'order' => 'DESC', 'include' => array(),
'exclude' => array(), 'meta_key' => '',
'meta_value' =>'', 'post_type' => 'job',
'suppress_filters' => true));
foreach($allposts as $postinfo) {
$wpdb->delete('rule', array('post_id' => $postinfo));
}
}
add_action('wp_trash_post', 'delete_condition', 10, 1);
感謝