Created
June 15, 2012 21:22
-
-
Save stresslimit/2938770 to your computer and use it in GitHub Desktop.
Almost working: recursively pre-populate taxonomy terms
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
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