• Im trying to show only the childs of a custom category.

    I’m using this code to list child categories:

    <?
    			$caats = wp_get_post_terms( $post->ID, 'categoria_produtos');
    			$customPostTaxonomies = get_object_taxonomies('produtos');
    
    			if(count($customPostTaxonomies) > 0)
    			{
    			     foreach($customPostTaxonomies as $tax)
    			     {
    				     $args = array(
    			         	  'orderby' => 'name',
    				          'show_count' => 0,
    			        	  'pad_counts' => 0,
    				          'hierarchical' => 1,
    			        	  'taxonomy' => $tax,
    			        	  'title_li' => '',
    			        	  'child_of' => $caats[0]->parent
    			        	);
    
    				     wp_list_categories( $args );
    			     }
    			}
    
    		?>

    is there anything wrong with it? i cant find the problem

Viewing 2 replies - 1 through 2 (of 2 total)
  • you must check in wp-admin what is a ID for PARENT category. In categories list click on it and check in URL id.

    Display category child for Parent category example Parent have id 12

    <?php
    $categories = wp_list_categories('title_li=&child_of=12&show_count=1&echo=0&orderby=ID');
    $categories = preg_replace('/<\/a> \(([0-9]+)\)/', ' <span class="count">(\\1)</span></a>', $categories);
    ?>

    Thread Starter ramonbjj

    (@ramonbjj)

    In fact I have a menu using the categories and a submenu with their subcategories. When I’m on a category i’d like to show only it’s childs but its listing all childs with their category

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show only childs of custom category’ is closed to new replies.