Skip to content

Instantly share code, notes, and snippets.

@trangsihung
Forked from hinnerk-a/wp_update_term.php
Created December 29, 2015 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trangsihung/70412b0287a3810e40a4 to your computer and use it in GitHub Desktop.
Save trangsihung/70412b0287a3810e40a4 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 ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment