[wp-trac] [WordPress Trac] #63307: REST API: Returns incorrect post when querying by slug if sticky posts exist

WordPress Trac noreply at wordpress.org
Thu Apr 24 10:24:28 UTC 2025


#63307: REST API: Returns incorrect post when querying by slug if sticky posts
exist
------------------------------------------------+--------------------------
 Reporter:  wpmudevsupport13                    |       Owner:  (none)
     Type:  defect (bug)                        |      Status:  new
 Priority:  normal                              |   Milestone:  Awaiting
                                                |  Review
Component:  REST API                            |     Version:  6.8
 Severity:  normal                              |  Resolution:
 Keywords:  changes-requested has-testing-info  |     Focuses:  rest-api
------------------------------------------------+--------------------------
Changes (by SirLouen):

 * keywords:  changes-requested has-testing-info 2nd-opinion has-patch
     needs-testing => changes-requested has-testing-info


Comment:

 == Patch Test Report
 === Description
 ❌ This report can't validate that the indicated patch works as expected.

 Patch tested: https://github.com/WordPress/wordpress-
 develop/pull/8730.diff

 === Environment
 - WordPress: 6.9-alpha-60093-src
 - PHP: 8.2.28
 - Server: nginx/1.27.5
 - Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
 - Browser: Chrome 135.0.0.0
 - OS: Windows 10/11
 - Theme: Twenty Fifteen 4.0
 - MU Plugins: None activated
 - Plugins:
   * Test Reports 1.2.0

 === Bug Reproduction Steps

 - Using URL like:
 1. ✅ Single post: https://example.com/wp-json/wp/v2/posts?slug=test-post
 2. ✅ All posts: https://example.com/wp-json/wp/v2/posts
 3. ❌ Template listings (i.e., Author): https://example.com/wp-
 json/wp/v2/posts?author=1 => If the author has an sticky post, it should
 appear in first position

 === Actual Results

 1. ✅ For the condition in the reporting post, this patch solves
 1. ❌ Some other scenarios are not solved.

 === Additional Notes
 I think that the only affecting filter is `slug`. The other filters should
 return the "stuck" post if there is a sticky post among the filtered
 results. Examples: If there are 10 posts, 2 of which are sticky
 1. If the user is using "exclude" with one of the sticky posts, it should
 return, the other sticky post on top, and the other non-sticky posts in
 the bottom
 2. If the user is using "include" with one sticky post and one non-sticky
 post, it should return, first the sticky one and second the non-sticky
 one, regardless of the ordering selected.

 Conclusion for the correct behavior:
 For anything listing ⇒ If the listing has sticky posts the should go first
 For anything single ⇒ Just show the single post.

 I'm going to be adding some unit tests so whoever builds the patch, takes
 all this into consideration.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63307#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list