Display all the subcategories from a specific category

Display all the subcategories from a specific category

In this post we will show you how to >Display all the subcategories from a specific category. At some point when utilizing WordPress custom menu, you would prefer not to include the tyke class from parent classification into the made menus. Be that as it may you need the tyke classification to indicate when you are perusing guardian class, this is helpful on the off chance that you have a wide assortment of sub-class for a specific classification.

In this post-exercise of > Display all the subcategories from a specific category, its simple to demonstrate all the subclasses from the present parent classification you are seeing. Simply include this bit code into anyplace you need in format, ideally in sidebar or someplace close to the route menus.

Display all the subcategories from a specific category by ID

function subcats_from_parentcat_by_ID($set_parent_cat_ID) {
$get_args = array(
'hierarchical' => 1,
'taxonomy' => 'product_cat'
'parent' => $set_parent_cat_ID,
'hide_empty' => 0,
'show_option_none' => '',
);
$get_subcats = get_categories($get_args);
echo '<ul class="wooc_sclist">';
foreach ($get_subcats as $sc_val)
{
$get_link = get_term_link( $sc_val->slug, $sc_val->taxonomy );
echo '
<li><a href="'. $get_link .'">'.$sc_val->name.'</a></li>

';
}
echo '</ul>

';
}

Display all the subcategories from a specific category by NAME

function subcats_from_parentcat_by_NAME($get_parent_cat_NAME)
{
$getIDbyNAME = get_term_by('name', $get_parent_cat_NAME, 'product_cat');
$get_product_cat_ID = $getIDbyNAME->term_id;
$get_args = array(
'hierarchical' => 1,
'taxonomy' => 'product_cat'
'parent' => $get_product_cat_ID,
'hide_empty' => 0,
'show_option_none' => '',
);
$get_subcats = get_categories($get_args);
echo '
<ul class="wooc_sclist">';
foreach ($get_subcats as $sc_val)
{
$get_link = get_term_link( $sc_val->slug, $sc_val->taxonomy );
echo '
<li><a href="'. $get_link .'">'.$sc_val->name.'</a></li>

';
}
echo '</ul>

';
}

OUTPUT for WordPress get catagory and subcatagory

As a rule, you will be including top level parent class into your custom menu yet all the others kid and grandchild classification will be escaped the site so clients won’t have the capacity to peruse them.

// output of WordPress get category and subcategory
catagory 1
-  subcatagory 1
-  subcatagory 2
-  subcatagory 3
catagory 2
-  subcatagory 4
-  subcatagory 5
catagory 3
-  subcatagory 6
catagory 4
-  subcatagory 7

Hope this code and post will help you to implement WordPress get a category and subcatagory. if you need any help or any feedback give it in the comment section or you have a good idea about this post you can give it in the comment section. Your comment will help us to help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

3  +  3  =  

We accept paid advance and paid guest Posting on our Site : Contact US