Get parent taxonomies/categories from child category

[themify_is_logged_in]

[php]

function parent_category_add( $post_id ) {

// get all assigned terms
$terms = wp_get_post_terms( $post_id );
foreach( $terms as $term ){
while( $term->parent != 0 && !has_term( $term->parent, $post ) ){
// move upward until we get to 0 level terms
wp_set_post_terms( $post_id, array( $term->parent ), true );
$term = get_term( $term->parent );
}
}
}
add_action( ‚wpuf_add_post_after_insert‘, ‚parent_category_add‘, 10, 1 );
add_action( ‚wpuf_edit_post_after_update‘, ‚parent_category_add‘, 10, 1 );

[/php]

[/themify_is_logged_in]