Get Only Parent Custom Post Type Category

cat

Examples – Only Parent Caetgory

<!--?php $args1 = array('orderby'=>'name','hide_empty'=>false,'parent'=>0);<br ?--> $taxonomy = "product_cat";
$allcat = get_terms( $taxonomy,$args1 );
foreach ($allcat as $allcats)
{
if($allcats->parent==0) :
echo get_term_link( $allcats->slug, $taxonomy );
echo $allcats->name;
echo $allcats->slug;
endif;
}
?>

Examples – Only Child Caetgory

 

<?php
$args1 = array('orderby'=>'name','hide_empty'=>false,'parent'=>0);
$allcat = get_terms( $taxonomy,$args1 );
foreach ($allcat as $allcats)
{
$args11 = array('orderby'=>'term_order','hide_empty'=>false,'child_of'=> $allcats->term_id,);
$myterms = get_terms($taxonomy, $args11);
if(count($myterms) != 0)
{
?>
<ul class=" cf" id="<?php echo $allcats->slug;?>">
<?php
foreach ($myterms as $myterm)
{
?>
<li><a href="<?php echo get_term_link( $myterm->slug, $taxonomy ); ?>" ><?php echo $myterm->name; ?></a></li>
<?php
} ?>
</ul>
<?php
}
}
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s