存档所有类别来自CPT和所有CPT类别的嵌套帖子

So I'm building my own Knowledgebase in WordPress. Most of the plugins are just too fat for my requirements.

Basically, I've setup my Custom Post Type and I've created categories and posts but I can't for the life of me nest posts under the relative categories.

I want my archive page to display ALL my categories for the CPT and then nest the posts relative to them categories. I've got the first step, just not the last and I don't understand what I'm doing wrong.

Code:

<?php
$taxonomy = 'category';
$terms = get_terms($taxonomy); // Get all terms of a taxonomy
if ( $terms && !is_wp_error( $terms ) ) :
?>
    <?php foreach ( $terms as $term ) { ?>
        <pre><?php print_r($term); ?></pre>
        <div class="article">
            <div class="article__box">
                <div class="article__header"><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></div>
                <div class="article__content">
                <?php
                $posts_array = get_posts(
                    array( 'showposts' => -1,
                    'post_type' => 'knowledgebase',
                    'tax_query' => array(
                            array(
                                'taxonomy' => 'category',
                                'fields' => $term->id,
                                'terms' => $term->name,
                            )
                        )
                    )
                );
                print_r( $posts_array ); 
                ?>
                </div>
            </div>
        </div>
    <?php } ?>
<?php endif;?>
</div>

Desired effect: http://prntscr.com/l7opcu

Currently have: http://prntscr.com/l7opqu