Create more category hierarchical depth for custom post type/taxonomy plugin (widget)

Source: http://getplatypi.com/docs/

A little new to the plugin development world, but so far I am building a post type plugin to support hierarchical categories in a list form with multiple depth levels (the structure I want is similar to: http://msdn.microsoft.com/en-us/library/windows/apps/br211362.aspx). The issue is although I can retrieve all post categories under the top parent category, it doesn’t show depth levels if there are multiple sub category levels. I want to allow as much depth as needed and create a list to show for it. For example, right now in the WP Admin I have the category structure:

Read More
Parent
- Child Category
-- Sub category of the child category
--- another level of category
- 2nd Child Category

But when I assign the posts to the categories above, the sidebar/widget that displays the posts will only display them underneath the Parent only and not in a hierarchical tree:

Parent
- Posts in Child Category
- Posts in Sub category of the child category
- Posts assigned to another level of category
- Posts in 2nd Child Category

Instead I want it to mimic the depth and hierarchical structure as the categories set up in the backend… Below is the PHP code I am using for the widget… not sure how to modify it.

foreach ( $sorted_termchildren as $child_id => $order ) {
        $termobject = get_term_by( 'id', $child_id, 'isa_docs_category' );
        //Display the sub Term information, in open widget container
        //echo '<aside class="widget well"><h3 class="widget-title">' . $termobject->name . '</h3>';
        echo '<ul>';
        // nest a loop through each child cat's posts
        global $post;
        $args = array(  'post_type' => 'isa_docs', 
                    'posts_per_page' => -1,
                    'order' => 'ASC',
                    'tax_query' => array(
                                array(
                                    'taxonomy' => 'isa_docs_category',
                                    'field' => 'id',
                                    'terms' => $termobject->term_id
                                    )
                                ),
                    'orderby' => 'meta_value_num',
                    'meta_key' => '_odocs_meta_sortorder_key',
                    'order' => 'ASC'
            );
        $postlist = get_posts( $args );
        foreach ( $postlist as $single_post ) {
                echo '<li';
                if( $single_post->ID == $current_single_postID ) 
                    echo ' class="organized-docs-active-side-item"';
                echo '><a href="' . get_permalink( $single_post->ID ) . '" title="' . esc_attr( $single_post->post_title ) . '">' . $single_post->post_title . '</a></li>';
        } 
                echo '</ul>';
    } // end foreach ( $sorted_termchildren

Otherwise, is there simply another plugin that does this already? I’ve searched everywhere. I would like to create this myself, just not sure how to make the code work accordingly. How can I fix this?

Related posts

Leave a Reply