You can use the parent
argument in get_terms()
to get direct children of a term.
You can use the child_of
argument to get all descendents of a term.
Something like this.
$parent_id = 32;
$args = array(
'parent' => $parent_id
);
$terms = get_terms( $taxonomy, $args );
print_r( $terms );
If you want to programmatically get parent terms and within the loop get sub-categories, you could do something like this.
$taxonomy = 'your_tax';
$args = array(
'parent' => 0 // to get only parent terms
);
$terms = get_terms( $taxonomy, $args );
foreach( $terms as $term ) {
$children = get_terms( $taxonomy, array(
'parent' => $term->term_id;
) );
print_r( $children );
}
Related Posts:
- How to add images to taxonomies?
- Custom Taxonomy and Tax_Query
- How to modify the query in taxonomy-custom.php to sort term archives by a custom meta field?
- SQL QUERY needed to get POST category (taxonomy) ? – MUST be SQL statement
- Combine multiple custom user taxonomy in single url
- Advanced Tax Query
- Improving WP_Query performance for multiple taxonomies
- Taxonomy , subtaxonomy,child taxonomy of a product woocommerce
- How can I display all post IDs from the taxonomy?
- Get ID and slug from taxonomy object
- How to display custom taxonomy in multiple columns?
- Custom taxonomies making WP very slow – Way to fix?
- How to count the number of terms in a taxonomy
- Sorting taxonomy columns by meta value numeric
- Get Taxonmy Term ID For Current Post
- Advanced Query Logic With Multiple Taxonomies
- Display only first level children of my custom taxonomy categories
- Is it possible to get all term items from a custom taxonomy regardless of post attachment status?
- Changing stylesheet depending on custom taxonomy terms
- How do I taxonomy terms based on terms they are used alongside?
- Custom taxonomy [year] is directing to yearly archive
- Get posts by term slug only
- Taxonomies on custom taxonomies
- Add Custom Taxonomy for Blog Meta Info
- Search Tool only refreshes Page without showing results
- Getting associated taxonomies
- How to fetch the data from Advanced Custom post when we search specific keyword or field name related to the post?
- How to add images to taxonomy terms? [duplicate]
- one post per term taxonomy
- Show only the sub-categories (and their content) of the current custom taxonomy with ‘taxonomy.php’
- Using Advanced Custom Fields Relationship Field to select a taxonomy term
- Custom arguments in WP_Query
- check if a taxnomy queried in $wp_query?
- WP_Query tax_query – Show results if child has parent X
- Query custom taxonomy for category including children
- Variable Not Working Inside is_author() Array
- How to get related taxonomies based on a category with mysql query?
- Prioritise Pages over Taxonomy Term Root Archive, but not Taxonomy Term Child Archives
- Tracking the name of a custom taxonomy
- Add terms to a taxonomy archive from within the same taxonomy
- Is it possible to filter a taxonomy archive by other taxonomies that are on posts?
- Fill New Taxonomies
- Custom Taxonomies Archive Page 404
- WordPress taxonomy terms archive template help
- Make relation of custom taxomies
- List active taxonomy terms
- taxonomy query on front page
- How do you search for a post by custom taxonomy?
- Next/Previous links in custom taxonomy, where item may belong to multiple terms
- How to query authors by custom taxonomy?
- Adding a query var to taxonomy term archive – gets redirected to the other taxonomy archive page
- How to get multiple Taxonomies not All Taxonomies?
- WordPress Taxonomy Menu
- Primary Taxonomy for Post
- Get taxonomy image for Toolset custom taxonomy through Toolset Views Shortcode
- wp_get_object_terms count on taxonomies within an category archive
- List posts grouped by children of a custom taxonomy
- Make custom post type display with custom taxonomy in url
- Hook to filter based on form value and insert term
- Complex Taxonomy scheme
- Querying posts globally based on custom taxonomy with its own taxonomymeta table
- Foreach for get_the_terms for hierarchical taxonomy don’t repeat Top Level Terms if contains multiple Second Level Terms
- Is there a way to ‘Lock’ a Taxonomy?
- Return only the custom sub-term for custom post type, do not echo term-parent
- wp_insert_term is adding a term that has no name
- Connect Users and Taxonomies
- WordPress json api taxonomy index method
- Sort Custom Taxonomy Terms in admin by custom order
- Change in custom taxonomy permalink causes 404 error for another custom taxonomy
- Checking if a Page has an Associated Term?
- Displaying ACF image field [closed]
- Custom Taxonomies Cababilities
- How to show the a custom taxonomy term on single post metadata
- Sort order by slug for looped child terms of custom taxonomy
- Simple Filter between multiple taxonomys
- Add success message to category add screen
- Prevent users from adding taxonomy terms
- Changing select options based on previous select with PHP & AJAX
- Headers already sent warning in Admin source is media.php 3140
- How can I reduce amount of ifs and else ifs in this specific block of code?
- Get name of taxonomies of current page
- Geographic search with taxonomy structure [duplicate]
- SQL / wp_update_post: change post custom field to CPT post taxonomy
- Custom Permalink Structure for terms/taxonomies of custom post type
- register_taxonomy for both ‘Post’ & ‘Page’
- List one post only from each subcategory using get_posts?
- Search custom taxonomy via query-string?
- problem : Custom taxonomy template not showing
- WordPress not saving tags for custom taxonomy term description
- Display multiple taxonomies in a function
- Exporting Custom Taxonomy Description without Plugin
- How do I display post count of a custom post type with custom category taxonomy in wp_menu_nav?
- WordPress Main Menu with dynamic url
- wp_insert_post and custom taxonomy
- Best Method to Switch Between Terms (Custom Taxonomy)
- Getting the parent terms adds additional empty markup [closed]
- Using post type archive page for taxonomy archive
- Custom Fields link to other pages, not search
- Taxonomy archive link from term id
- Add taxonomy fields of posts into RSS feed