当父帖子被删除时,我正在尝试删除所有子帖子。
父帖子删除得很好,但子帖子没有正确删除。
以下是我现在掌握的代码:
$args = array(
\'post_parent\' => $parentid,
\'post_type\' => \'custom-type\'
);
$posts = get_posts( $args );
if ($posts) {
// Delete all the Children of the Parent Page
foreach($posts as $post){
wp_delete_post($post->ID, true);
}
}
// Delete the Parent Page
wp_delete_post($parentid, true);
它应该做的是循环并获取$parentid
并删除它们,然后删除父帖子。目前,它只删除父帖子,但保留所有子帖子。
我正在查看我的数据库,子页面肯定是用正确的post_parent
身份证件
有没有办法获取所有子帖子并将其删除?
谢谢
杰森