Add hierarchical taxonomy handling to wp_set_post_terms(). Props prettyboymp. see #10122

git-svn-id: http://svn.automattic.com/wordpress/trunk@12509 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-12-23 14:25:09 +00:00
parent 95835a693a
commit e7d9a6913a
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);
}