$topic_id, 'post_type' => 'reply', 'orderby' => 'menu_order', 'order' => 'asc', ] ); $reply_ids = ''; if ( is_array( $replies ) ) { foreach ( $replies as $reply ) { $reply_ids .= $reply->ID . ','; } } $topic_posts = $topic_id . ',' . $reply_ids; $topic_posts = explode( ',', $topic_posts ); $topic_posts_int = array_map( 'intval', $topic_posts ); foreach ( $topic_posts_int as $delete_topic ) { if ( ! empty( $delete_topic ) ) { wp_trash_post( $delete_topic ); } } wp_send_json_success( 'Topic Deleted successfully.' ); wp_die(); }