0
votes

On this page: http://realtor.kirkdahle.com/resources-test/ I have numerous categories and subcategories for a custom post type 'resources'. I am currently working to have the sidebar display the categories and subcategories and main body to show all posts.

All the posts are within the subcategories, organized by the main categories. If there isn't at least one post that ALSO checks the main category along with the subcategory then NOTHING is displayed in the list for the main category OR subcategories. Here is my code:

 <?php 
    // gets all categories 
    $taxonomies = array( 
        'resource-cat'
    );

    $taxonomy_name = 'resource-cat';

    $args = array(
        'orderby'           => 'name', 
        'order'             => 'ASC',
        'hide_empty'        => true, 
        'exclude'           => array(), 
        'exclude_tree'      => array(), 
        'include'           => array(),
        'number'            => '', 
        'fields'            => 'all', 
        'slug'              => '',
        'parent'            => '',
        'hierarchical'      => false, 
        'child_of'          => 0,
        'childless'         => false,
        'get'               => '', 
        'name__like'        => '',
        'description__like' => '',
        'pad_counts'        => false, 
        'offset'            => '', 
        'search'            => '', 
        'cache_domain'      => 'core'
    ); 

    $terms = get_terms($taxonomies, $args);

    echo '<ul id="top-cats">';
    foreach ($terms as $term) { 
        if(!$term->parent)
             echo '<li class="filter_bold"><a href="'.get_term_link( $term ).'">'.$term->name.'</a></li>';

        $termchildren = get_term_children( $term->term_id, $taxonomy_name );
        echo '<ul>';
        foreach ( $termchildren as $child ) {
            $subterm = get_term_by( 'id', $child, $taxonomy_name );
            if($subterm->count != 0)
                echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $subterm->name . '</a></li>';
        }
        echo '</ul>';
    }
    echo '</ul>';
  ?>

any suggestions on how to adjust this would be most appreciated.

1
Have you tried with offset => 0 with your query? - Ahmad Baktash Hayeri

1 Answers

0
votes

I solved it by changing

'hierarchical'      => 1,