From 02ce80a2847adfd86ed690b1d463bd68800bbf2c Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 23 Dec 2009 14:25:09 +0000 Subject: [PATCH] Add hierarchical taxonomy handling to wp_set_post_terms(). Props prettyboymp. see #10122 git-svn-id: https://develop.svn.wordpress.org/trunk@12509 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/post.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wp-includes/post.php b/wp-includes/post.php index f0427c16d3..f2622561d4 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2062,6 +2062,15 @@ function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $a $tags = array(); $tags = is_array($tags) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") ); + + // Hierarchical taxonomies must always pass IDs rather than names so that children with the same + // names but different parents aren't confused. + $taxonomy_obj = get_taxonomy( $taxonomy ); + if ( $taxonomy_obj->hierarchical ) { + $tags = array_map( 'intval', $tags ); + $tags = array_unique( $tags ); + } + wp_set_object_terms($post_id, $tags, $taxonomy, $append); }