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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -