From 04b0ec782b756d95e80ad95128763ae684ef601f Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 12 Jul 2014 03:53:34 +0000 Subject: [PATCH] The 2nd argument to `array_unique()` was added to PHP in 5.2.9, so don't use it. We have to use our own code to return unique terms when `fields => all` in `wp_get_object_terms()`. See #28843 and [28583]. git-svn-id: https://develop.svn.wordpress.org/trunk@29119 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/taxonomy.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 31810c1a98..0b24d56623 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -2321,6 +2321,7 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order"; + $objects = false; if ( 'all' == $fields || 'all_with_object_id' == $fields ) { $_terms = $wpdb->get_results( $query ); foreach ( $_terms as $key => $term ) { @@ -2328,6 +2329,7 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { } $terms = array_merge( $terms, $_terms ); update_term_cache( $terms ); + $objects = true; } else if ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) { $_terms = $wpdb->get_col( $query ); $_field = ( 'ids' == $fields ) ? 'term_id' : 'name'; @@ -2344,8 +2346,20 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { if ( ! $terms ) { $terms = array(); - } else { - $terms = array_values( array_unique( $terms, SORT_REGULAR ) ); + } elseif ( $objects && 'all_with_object_id' !== $fields ) { + $_tt_ids = array(); + $_terms = array(); + foreach ( $terms as $term ) { + if ( in_array( $term->term_taxonomy_id, $_tt_ids ) ) { + continue; + } + + $_tt_ids[] = $term->term_taxonomy_id; + $_terms[] = $term; + } + $terms = $_terms; + } elseif ( ! $objects ) { + $terms = array_values( array_unique( $terms ) ); } /** * Filter the terms for a given object or objects.