#41010 closed defect (bug) (fixed)
wp_get_object_terms() returns duplicate terms if more than one taxonomy is given in args
Reported by: | mranner | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.8.1 | Priority: | normal |
Severity: | normal | Version: | 4.8 |
Component: | Taxonomy | Keywords: | has-patch dev-feedback commit |
Focuses: | Cc: |
Description
works correct
$list = wp_get_object_terms([ 104627 ], [ 'produkte' ]);
print_r($list);
returns all terms for produkte and herkunft and merges all terms related to the post
$list = wp_get_object_terms([ 104627 ], [ 'produkte', 'herkunft' ]);
print_r($list);
Problem is unset( $taxonomies[ $index ] ) followed by $terms = array_merge( $terms, get_terms( $args ) );
foreach ( $taxonomies as $index => $taxonomy ) {} iterates for all given taxonomies and leaves an empty $taxonomies array. get_terms() with an empty array for $argstaxonomy? returns "all" related terms and merges with the terms of the previews loop run.
Michael
Attachments (3)
Change History (14)
#2
@
7 years ago
- Keywords has-patch added
Please use the following code to reproduce: https://gist.github.com/bor0/109e091c4aa625cbe670766db53ae5e1.
#4
@
7 years ago
@peterwilsoncc sounds good to me.
I'll try to supply a UT sometime today or tomorrow.
In the meanwhile, can you assign a milestone for this so that it doesn't get lost?
Thanks!
#6
@
7 years ago
- Keywords needs-unit-tests removed
I've added a unit test to the patch with comments about what triggers the error (the unsupported "args" key).
Not sure about the test name - it probably needs a better one.
#7
@
7 years ago
- Keywords dev-feedback added
- Milestone changed from 4.9 to 4.8.1
@bor0 and @atanasangelovdev - Thanks for the patch and especially for the unit test, which helped me to understand the issue better.
This is a regression caused by [40514] in 4.7.5. For this reason, I think it's appropriate to fix in 4.8.1. In order to include in a minor release, I'd appreciate a review by another committer. @peterwilsoncc Since you've commented here, would you mind verifying the issue and the fix offered in 41010.3.patch (which does some slight modification to the code style in the unit test to better align with WP standards)?
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
7 years ago
#9
@
7 years ago
- Keywords commit added
@boonebgorges,
I've checked this out, verified the issue exists and the fix works.
I'm not sure I follow the latter half of your issue. I've tested
wp_get_object_terms()
with Postarray( 'category', 'post_tag' );
and I get the expected results, no duplicates. Can you list steps to reproduce this issue?