Use get_the_terms to list subcategories of custom taxonomy

Currently I use the following code to output all categories within this custom taxonomy in a custom post type:

<?php
$args = array(
‘post_type’ => ‘video_cpt’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => -1,
‘orderby’ => ‘publish_date’,
‘order’ => ‘DESC’,
);

$video_query = new WP_Query( $args );

$videos_post_objects = $query;

while ($video_query->have_posts()) {
$video_query->the_post();
$terms = get_the_terms( $post->ID, ‘video_categories’ );
$term = array_shift( $terms );
}
?>

Is it possible to use get_the_terms (preferably by name instead of taxonomy ID) in the same manner to get the subcategories of a category from a custom taxonomy in a custom post type?

ie.

video categories
fruits
apples
oranges
bananas
vegetables
lettuce
kale
broccoli

how would I use get_the_terms (in a similar way as above) to only list out apples, oranges, bananas?

Read more here:: Use get_the_terms to list subcategories of custom taxonomy

Leave a Reply

Your email address will not be published. Required fields are marked *