• CUSTOM POST TYPE:

    • product

    TAXONOMY:

    • product-category
    • brands

    The question is, How can I have a sidebar where the parent is the BRAND and under this parent the CATEGORIES in HIERARCHICAL mode (the categories & subcategories should be related to “the parent“).

    For now I`m using this code:

    $output = '<ul>';
    
    $brands = get_terms('brands');
    $count = count($brands);
    if ( $count > 0 ):
    
    	foreach($brands as $brand):
    
    		$output .= '<li>'.$brand->name.'</li>' ;
    
    		$args = array('post_type' => 'product', 'brands'=>$brand->slug ,'post_status' => 'publish', 'posts_per_page'=>'1000', 'orderby' => 'name');
    		$products = get_posts( $args );
    
    		foreach( $products as $post ) : setup_postdata($post);
    
    			$p_categories = get_the_term_list($post->ID, 'product-category','<li>', '</li><li>', '</li>');
    
    		endforeach;
    		wp_reset_postdata();
    
    		$output .= '<ul>'.$p_categories.'</ul>';
    
    	endforeach;
    
    endif;
    
    $output .= '</ul>';
    
    echo $output;

    This code works, but the categories are not hierarchicle. Any IDEEA ?

  • The topic ‘Hierarchicle Custom Post Type | ( get_the_term_list() ? hierarchical )’ is closed to new replies.