Repository navigation
Conversation
…njection. See #63360.
…_in and category__not_in. See #63360.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
What
Trac ticket: https://core.trac.wordpress.org/ticket/63360
When
WP_Queryinjects sticky posts at the top of home-query results, the subquery that fetches stickies missing from the result set ignores the constraints of the current query. Becauseauthor__in,post_name__in,category__not_in,tag__not_in,tax_query,meta_queryand similar arguments do not set theis_author/is_category/... conditionals, the query is treated asis_home, and all published sticky posts get prepended — including stickies by other authors or with other slugs than the ones explicitly requested.Reproducer from the ticket (Query 3 and Query 4 of the wp-query-tester plugin):
Fix
Carry the constraining query vars from the current query into the sticky-fetch
get_posts()call, so only stickies that match the explicit filters are injected. Stickies still come first, but explicit filters are now honored.The carried vars are the constraint-style arguments that can be set while
is_homeremains true:author__in,author__not_in,post_name__in,category__in,category__not_in,category__and,tag__in,tag__not_in,tag__and,tag_slug__in,tag_slug__and,post_parent,post_parent__in,post_parent__not_in,tax_query, andmeta_query. Scalar constraints that set their own conditional (author,cat,tag,name, date parts,s) never reach this code path, since the sticky block only runs foris_homequeries.post__inis deliberately not touched: its documented behavior is that sticky posts are prepended regardless.Tests
Three new tests in
tests/phpunit/tests/query/stickies.php:test_stickies_should_obey_author__in— stickies by other authors are not injected; a matching sticky is still moved to the top (fails on trunk).test_stickies_should_obey_post_name__in— a slug query returns only the requested post (fails on trunk).test_stickies_should_obey_category__not_in— stickies in an excluded term are not injected (fails on trunk).Test results
Tests_Query_Stickies: 10/10 pass, including the pre-existing sticky-order andpost__not_intests.WP_Test_REST_Posts_Controller: 288 tests, 2642 assertions, OK (no change to theignore_stickybehavior added in [59801]/[60197]).