Displaying Custom Post Types in hirearchy with only chlid list being displayed
-
I have created a Custom Post Type – Products and a Custom Category – Product Categories for the same. Product Categories are in hierarchy with up to 4 levels. I have displayed the Primary Product Categories on a custom page for products. On clicking the primary Product Categories it is directed to the taxonomy-product_categories.php page, which display the child categories of the primary Product Categories which was clicked. Now the problem starts, when secondary Product Categories is clicked its process on the same page but does not give its child categories but instead throws back the same Product Categories that were displayed previously and does not move to its child categories.
Following is the code that i have used in the taxonomy-product_categories.php page<?php $args=array( 'post_type' => 'products', 'child_of' => $cat->ID, 'parent' => $cat->ID, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'number' => '', 'depth' => 0, 'taxonomy' => 'product_categories', 'pad_counts' => false ); $categories=get_categories($args); echo '<div class="fixed-row clearfix dynamic-fixedRow-735" id="row_order_2">'; foreach ( $categories as $category ) { if ( $category->parent > 0 ) { continue; } $deptID = $category->cat_ID; $childCatID = $wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent=$deptID"); if ($childCatID){ foreach ($childCatID as $kid) { $childCatName = $wpdb->get_row("SELECT name, term_id FROM $wpdb->terms WHERE term_id=$kid"); echo '<div class="box two first product box-shadow" style="min-height: 231px; margin-bottom:10px"> <h5><a href="' . get_term_link( intval($childCatName->term_id), 'product_categories' ) . '" title="' . sprintf( __( "View all posts in %s" ), $childCatName->name ) . '" ' . '>' . $childCatName->name.'</a> </h5> <div class="image-border-bottom"> </div> </div>'; echo '<div><a href="#">name ) . '" ' . '>' . $kid->name.'</a></div>'; } } } echo '</div>'; ?> <em>[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]</em>
- The topic ‘Displaying Custom Post Types in hirearchy with only chlid list being displayed’ is closed to new replies.