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
This commit is contained in:
parent
63cb20cc5a
commit
04b0ec782b
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue