I have custom post type called “Products”, and it has a taxonomy ‘Product Categories’ which has categories Category 1, Category 2 etc. which again has sub categories Category 1a, Category 2a etc. What i want is, when i click on Category 1,it should list the subcategories Category 1a, Category 2a etc. When clicking on Category 2a, it should list the products associated with the category. How can I accomplish this with wordpress?
<?php $taxonomy_name = 'al_product_cat';
$term_childs = get_term_children( $wp_query->get_queried_object_id(), $taxonomy_name ); //print_r($term_childs);
foreach($term_childs as $child){
$tm = get_term_by( 'id', $child, $taxonomy_name ); ?>
<div class="tax_content">
<div class="feat_thumb"></div>
<div class="feat_content">
<h2><a href="<?php echo get_term_link( $child, $taxonomy_name ); ?>"><?php echo $tm->name; ?></a></h2>
<p><?php echo $tm->description; ?> </p>
<div class="brand_logos">
<?php $terms = get_the_terms( $wp_query->get_queried_object_id(), 'brand' );
foreach($terms as $term){
?>
<img src="<?php echo z_taxonomy_image_url($term->term_id); ?>" />
<?php } ?>
</div>
</div>
<div class="clear"></div>
</div>
<?php } ?>
You can use WordPress Templates for this purpose.
Always use WP_Query() for custom post type and taxonomy.
Now create a file in your theme like
taxonomy-al_product_cat.php
and then write some code in this file.For example in taxonomy-al_product_cat.php
You can read about tax_query() and get_queried_object() from these links.
Hope this will help you.