Wordpress获取所选分类术语的自定义分类术语列表

How can I get all the custom taxonomy terms and the selected ones in a same function? I am using this function to get all the terms but it does not say which are selected for this post.

function get_terms_chekboxes($taxonomies, $args, $post_id) {
    $terms = get_terms($taxonomies, $args);
    foreach($terms as $term){
        $checked = ( is_category( $term->name ) ) ? 'checked="checked"' : '';
        $output .= '<label for="'.$term->slug.'"><input type="checkbox" id="'.$term->slug.'" name="aktivitet_categories[]" value="'.$term->name.'"> '.$term->name.'</label>';
    }
    return $output;
}

I am trying to build a list of checkboxes with the terms. I also want to show the selected ones while editing the post from front-end.