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
This commit is contained in:
Ryan Boren 2009-12-23 14:25:09 +00:00
parent 65658aacbf
commit 02ce80a284
1 changed files with 9 additions and 0 deletions

View File

@ -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);
}