Skip to content

Instantly share code, notes, and snippets.

@hinnerk-a
Created October 4, 2012 18:12
Show Gist options
  • Save hinnerk-a/3835366 to your computer and use it in GitHub Desktop.
Save hinnerk-a/3835366 to your computer and use it in GitHub Desktop.
Using wp_update_term properly for setting parent terms in hierarchical taxonomies
<?php
// set terms
wp_set_object_terms( $post_id, $object_types, 'immomakler_object_type', true );
// make terms hierarchial by objektart
$term_parent = get_term_by( 'slug', $openimmo_data['objektart'], 'immomakler_object_type' );
$term_child = get_term_by( 'slug', $openimmo_data['objektart_detail'], 'immomakler_object_type' );
delete_option( 'immomakler_object_type_children' ); // workaround for WordPress not updating this option properly
wp_update_term( $term_child->term_id, 'immomakler_object_type', array( 'parent' => $term_parent->term_id ) );
?>
@luisfdeandrade
Copy link

Nice gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment