New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: consider 'fields' value when returning terms from query #2806
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not have it when I wrote the code, but now I have ;-). Can add some in the the next days. |
b553edc
to
e64955a
Compare
@gchtr Resolved your comments and added a number of tests covering all possible return values of I tried to write the tests in a way that there is sort of an assertion problem with the old code that is now solved with my patch. I have to admit, I failed with that, as in the original code the root cause was the call of the |
e64955a
to
95af228
Compare
Did a few optimizaitons for the assertions (assertSame, not assertEquals etc) |
Thank you @jrathert! We just need to take a decision on #2806 (comment) And it will be good to go. |
95af228
to
fa95b91
Compare
Removed the unnecessary ' |
fa95b91
to
fd95ebb
Compare
I’m continuing the discussion we started in #2806 (comment) here. Very good that the issue with count popped up here.
I agree with that.
We could use This could mean that we could keep General error handling is still something we need to figure it in the future (#2210). |
I just talked to @nlemoine. We going to drop |
Some tests only fail because of an issue with testing against WordPress 6.4. For now, we can ignore these tests. I’m merging this in. |
Related:
Issue
A
fields
argument other thanall
orall_with_object_id
lead to a fatal error, asTermFactory::from_wp_term_query()
did expect the result of a query to always be of typeWP_term[]
Solution
In
TermFactory::from_wp_term_query()
callTermFactory::build()
only iffields
isall
orall_with_object_id
, otherwise, return plain result ofWP_Term_Query::get_terms()
(i.e.,int[]|string[]|string
)Considerations
One could - instead of examining the
fields
argument - check if the object returned fromWP_Term_Query::get_terms()
actually is aWP_Term[]
. That would be future proof (if there arefields
values added for which the query also returns an array ofWP_Term
) - but might have some impact on performance, so I decided to solve it this way.Testing
No specific