Skip to content

Instantly share code, notes, and snippets.

@sarahbayley
sarahbayley / gist:c7fe0f40491d2a28a026d8c6f6cf6a94
Last active March 7, 2021 06:49
Copy WP (child) terms to another taxonomy. Example copies children of term with ID '32' in the taxonomy 'category' (i.e. all my Vocab subcategories) to the custom taxonomy 'sets'. Use in functions.php.
$term_id = 32;
$from_taxonomy = 'category';
$to_taxonomy = 'sets';
$termchildren = get_term_children( $term_id, $from_taxonomy );
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $from_taxonomy );
$name = $term->name;