From c4809250ca29f13b06673fa2db688bf5ecda685c Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 13 Jul 2017 13:43:33 +0000 Subject: [PATCH] Taxonomy: Avoid duplicates when querying for terms in taxonomies registered with `$args` parameter. [40514] introduced a bug that caused term queries to return some duplicates when the `$taxonomies` array contained only taxonomies that were originally registered with an `$args` array. We fix this bug by ensuring that recursive `get_terms()` queries stop when all queried `$taxonomies` have already been referenced. Ports [41037] to the 4.8 branch. Props bor0, atanasangelovdev. Fixes #41010. Built from https://develop.svn.wordpress.org/branches/4.8@41038 git-svn-id: http://core.svn.wordpress.org/branches/4.8@40888 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index f1c1bce307..f69169343e 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1864,7 +1864,10 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { $args['taxonomy'] = $taxonomies; $args['object_ids'] = $object_ids; - $terms = array_merge( $terms, get_terms( $args ) ); + // Taxonomies registered without an 'args' param are handled here. + if ( ! empty( $taxonomies ) ) { + $terms = array_merge( $terms, get_terms( $args ) ); + } /** * Filters the terms for a given object or objects.