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].

Built from https://develop.svn.wordpress.org/trunk@29119


git-svn-id: http://core.svn.wordpress.org/trunk@28905 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-07-12 03:54:15 +00:00
parent 40725e9e67
commit fabec026c2

View File

@ -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.