Get children of taxonomies
-
22-04-2021 - |
Question
$terms = get_terms([
'taxonomy' => array('Movies, Musics, Books, Games'),
'parent' => 0,
'depth'=> 2,
'hide_empty' => false,
]);
$sorted_terms = [];
if ( $terms ) {
foreach ( $terms as $term ) {
$sorted_term = [
'WP_Term' => $term, // the global term
'icon' => get_field( 'logo', $term->taxonomy . '_' . $term->term_id ),
'srating' => get_field( 'rating', $term->taxonomy . '_' . $term->term_id ),
'carrentActiveClass' => '',
'count' => (int) wpse340250_term_count( $term, 'sikayet' ),
// everything you will need later here
];
///// and my code continue
in the above code I can get terms of different taxonomies. But I am trying to get children of taxonomy terms. Can any one help me please
'parent' => 0,
'depth'=> 2,
did not work
Solution
not actually sure what you are trying to achieve with the code. I would write something like this to get the child terms
$terms = get_terms([
'taxonomy' => array('Movies, Musics, Books, Games'),
'parent' => 0,
'hide_empty' => false,
]);
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
foreach ($terms as $term) {
$child_term = get_term_children( $term->term_id, $term->taxonomy )
//your code here
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange