Created
December 1, 2019 05:47
-
-
Save hamedmoody/8835d01afbeef80cbee647327e493bf8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = [ | |
'taxonomy' => 'category', | |
'hide_empty' => 0, | |
'parent' => 0 | |
]; | |
function _get_child_terms( $items ) { | |
foreach ( $items as $item ) { | |
$item->children = get_terms( 'category', array( 'child_of' => $item->term_id, 'hide_empty' => 0 ) ); | |
if ( $item->children ) _get_child_terms( $item->children ); | |
} | |
return $items; | |
} | |
$terms = _get_child_terms( get_terms( $args ) ); | |
wp_send_json( $terms ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment