wordpress - Is there a way to make child posts inherit parent post terms? -
i have few custom posts go parent great grand children. assign parent post term custom taxonomy of child posts inherit. there way this? otherwise, have apply term each post, daunting task.
if create post wordpress ui add functions.php , need:
function set_parent_terms( $post_id, $post ) { if ( 'publish' === $post->post_status && $post->post_parent > 0 ) { $parent = get_post($post->post_parent); if(!empty($parent)){ $taxonomies = get_object_taxonomies( $parent->post_type ); foreach ( (array) $taxonomies $taxonomy ) { $terms = wp_get_post_terms( $parent->id, $taxonomy ); if ( !empty( $terms ) ) { $termarr = array_map(create_function('$obj', 'return $obj->term_id;'), $terms); $tmp = wp_set_object_terms( $post_id, $termarr, $taxonomy, true ); } } } } } add_action( 'save_post', 'set_parent_terms', 100, 2 ); if creating post using wp_insert_post dont know how make work
Comments
Post a Comment