[wp-trac] [WordPress Trac] #28099: Empty array passed to WP_Query post__in returns posts
WordPress Trac
noreply at wordpress.org
Thu Aug 10 19:44:08 UTC 2023
#28099: Empty array passed to WP_Query post__in returns posts
-------------------------------------+------------------------------
Reporter: danielbachhuber | Owner: wonderboymusic
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Query | Version:
Severity: normal | Resolution:
Keywords: 2nd-opinion needs-patch | Focuses:
-------------------------------------+------------------------------
Changes (by azaozz):
* keywords: has-patch => 2nd-opinion needs-patch
Comment:
Replying to [comment:39 pikamander2]:
> If there's any way to rip off the band-aid and make passing 0 actually
return 0 posts, I think that would be the best way forward.
> ...
> 1. Temporarily throw a deprecation warning in an upcoming release when 0
is passed...
>
> 2. In a release sometime after that, remove the deprecation warning and
make 0 actually return 0 posts.
I tend to agree with @dd32's assessment from 13 years ago:
https://core.trac.wordpress.org/ticket/12212#comment:10. The fact that
non-existing `post__in` is filled with an empty array is a quirk in
WP_Query.
However what would be the purpose to query posts when you want to not find
any? Its the same as driving to the grocery store with a shopping list
with zero items on it, then buying nothing and returning empty handed :)
> the post__in array(0) hack no longer works, but rather shows all posts
just like the empty array
Is there a better way to do what you need to do without having to use "a
hack" and run a query for zero items?
Thinking this can be seen as a regression of "doing-it-wrong" (unintended)
use. Seems the "post__in array(0)" hack will have to be restored. However
thinking a "Doing it wrong" would also be needed there.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28099#comment:41>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list