我有一个函数可以删除帖子及其子项。我怎样才能修改它来删除它的孙子呢?
<?php
function delete_post($sectionid)
{
global $post;
$deletepostlink= add_query_arg( \'frontend\', \'true\', get_delete_post_link( $sectionid) );
if (current_user_can(\'edit_post\', $sectionid)) {
echo \'<span><a class="post-delete-link" onclick="return confirm(\\\'Are you sure to delete?\\\')" href="\' . $deletepostlink . \'">Delete this </a> </span>\';
}
}
//Redirect after delete post in frontend
add_action(\'trashed_post\',\'trash_redirection_frontend\');
function trash_redirection_frontend($post_id )
{
if ( filter_input( INPUT_GET, \'frontend\', FILTER_VALIDATE_BOOLEAN ) ) {
$args = array(
\'posts_per_page\' => -1,
\'order\'=> \'ASC\',
\'post_parent\' => $post_id,
\'post_type\' => \'bucket\'
);
// Filter through all pages and find Portfolio\'s children
$children = get_children( $args );
global $wpdb;
foreach($children as $child){
$childs[$child->ID] = $child->ID;
}
$sql = "UPDATE {$wpdb->posts} SET post_status = \'trash\' WHERE ID IN (" . implode( \', \', $childs ) . ")";
$wpdb->query($sql);
$referer = $_SERVER[\'HTTP_REFERER\'];
wp_redirect( $referer );
exit;
}
}
我需要另一个foreach
, 但到目前为止,我的PHP只是基本的。