show Only Parent Categories of custom taxonomy in wordpress

 <?php
                                            $taxonomy     = 'product_cat';
                                            $orderby      = 'name'; 
                                            $show_count   = 0;   
                                            $pad_counts   = 0;   
                                            $hierarchical = 1;     
                                            $title        = ''; 
                                            $empty        = 0;
                                            $args = array(
                                            'taxonomy'     => $taxonomy,
                                            'orderby'      => $orderby,
                                            'show_count'   => $show_count,
                                            'pad_counts'   => $pad_counts,
                                            'hierarchical' => $hierarchical,
                                            'title_li'     => $title,
                                            'hide_empty'   => $empty,
'exclude' =>25  /* hide Uncategorized*/
                                            );
                                            ?>

   <ul id="cat_accordion" class="ohter-categories">
                                <?php
                                        $all_categories = get_categories( $args );
                                        foreach ($all_categories as $cat) {
                                        if($cat->category_parent == 0) {
                                $category_id = $cat->term_id; 
?>
                                  <li><a href="<?php echo get_term_link($cat->slug, 'product_cat'); ?>"><?php echo $cat->name; ?></a>  </li>
                                   <?php 
        }     
                                        }
                                        ?>
                                </ul>

Comments

Popular posts from this blog

dynamic create multiple ckeditor onclick event using jquery

get lat and long from city name using jquery

membership registration and login system in php