Skip to content

Instantly share code, notes, and snippets.

@stresslimit
Created June 15, 2012 21:22
Show Gist options
  • Save stresslimit/2938770 to your computer and use it in GitHub Desktop.
Save stresslimit/2938770 to your computer and use it in GitHub Desktop.
Almost working: recursively pre-populate taxonomy terms
add_action( 'init', 'sld_prepopulate' );
function sld_prepopulate() {
$terms = array(
'term1',
'term2',
'Faculty' => array(
'booze',
'jeans',
),
'other',
);
function sld_insert_terms( $terms, $taxonomy, $parent = 0 ) {
$args = array( 'parent' => $parent );
foreach ( $terms as $k => $v ) {
if ( is_array( $v ) ) {
echo " parent = wp_insert_term( $k, $taxonomy, $args )";
$parent = wp_insert_term( $k, $taxonomy, $args );
die(var_dump($parent));
echo "sld_insert_terms( $v, $taxonomy, {$parent->term_id} )";
sld_insert_terms( $v, $taxonomy, $parent->term_id );
} else {
wp_insert_term( $v, $taxonomy, $args );
}
}
}
// sld_insert_terms( $terms, 'staff-type' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment