trangsihung
12/29/2015 - 3:11 AM

Using wp_update_term properly for setting parent terms in hierarchical taxonomies

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 ) );

?>