Created
April 30, 2016 23:14
-
-
Save mrfoxtalbot/018137eeee59d9402431217d5eb65e40 to your computer and use it in GitHub Desktop.
Hacer que los posts hijos hereden los términos de los posts padres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Set Child Terms to Parent Terms **/ | |
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 as $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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment