Support » Fixing WordPress » Get child categories of custom taxonomy

  • Resolved GradyD

    (@adroidman)


    I have created a custom taxonomy which I can query for and get all the categories, parent and child, but I am wanting just the child elements. I used the below code to get the category ID,

    get_cat_ID( $cat_name='Apps1' );
    	    $cat = get_term_by( 'name', $cat_name, 'appCategory' );
          echo $cat -> term_id;

    This returned 50 which I included in my $args,

    $args = array(
            'orderby'            => 'id',
            'show_count'         => 0,
            'use_desc_for_title' => 0,
            'child_of'           => 50,
            'taxonomy'           => 'appCategory'
          );
          wp_list_categories($args);

    I also tried removing the taxonomy tag but so far I am only able to get it to display built-in wordpress post/categories and nothing from my custom post/taxonomy. How can I display the child elements for a custom taxonomy parent?

Viewing 1 replies (of 1 total)
  • Thread Starter GradyD

    (@adroidman)

    I was able to fix my issue. My cod is as follows,

    $args = array(
           'hide_empty'         => 0,
           'orderby'            => 'id',
           'show_count'         => 0,
           'use_desc_for_title' => 0,
           'child_of'           => $category
          );
          $terms = get_terms( 'appCategory', $args );
          if ( !empty( $terms ) && !is_wp_error( $terms ) ) {
            foreach ( $terms as $term ) {
              echo '<p>' . $term->name , '</p>';
              echo get_term_link($term);
            }
Viewing 1 replies (of 1 total)
  • The topic ‘Get child categories of custom taxonomy’ is closed to new replies.