Make WordPress Core

Opened 8 months ago

Last modified 6 months ago

#63360 new defect (bug)

ignore_sticky_posts generating a wrong behaviour in WP_Query

Reported by: sirlouen's profile SirLouen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: blocker Version: 6.8
Component: Query Keywords: needs-patch has-test-info
Focuses: Cc:

Description

Bug Report

Description

According to the docs:

ignore_sticky_posts (boolean) – ignore post stickiness (available since version 3.1, replaced caller_get_posts parameter). false (default): move sticky posts to the start of the set. true: do not move sticky posts to the start of the set.


Something is going wrong with ignore_sticky_posts behavior when certain WP_Query args are being used (the __in ones more specifically).

More importantly, since, ignore_sticky_posts is false by default, it can be easily reproduced as soon as we use any of these arguments for the query.

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 Twenty-Five 1.2
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Steps to Reproduce

  1. Install this simple plugin for testing: https://raw.githubusercontent.com/SirLouen/wp-query-tester/refs/tags/1.0.1/wp-query-tester.php
  2. Create a second username
  3. Create some posts in this order:
  • First post, make sticky
  • Second not sticky post. Call it exactly, "Not Sticky 1", with slug "not-sticky-1".
  • Third, make sticky post
  • Fourth not sticky post
  • Fifth a sticky post, with second username as author
  • Sixth, not sticky with second username as author
  1. Create another post and add the short code [wp_query_tester]
  2. 🐞 Bug occurs

Expected Results

  • Query 1: All posts with sticky on top
  • Query 2: All posts ignoring the stickyness
  • Query 3: All posts from Author 1
  • Query 4: The post with slug "not-sticky"

Actual Results

  1. Query 1 is ✅
  • Query 2 is ✅
  • Query 3 is ❌. Queried only author 1. A post from author 2 appears (because its sticky)
  • Query 4 is ❌. Queried just the slug not-sticky-1. All sticky posts appear, the last one is the one queried.

Additional Notes

This topic is seriously correlated with this issue #63307 just as a reference.

Supplemental Artifacts

Plugin repo: https://github.com/SirLouen/wp-query-tester/

Screenshot Sample

https://i.imgur.com/ILiKfgs.png

Change History (3)

This ticket was mentioned in Slack in #core-test by sirlouen. View the logs.


7 months ago

#3 @wordpressdotorg
7 months ago

  • Keywords has-test-info added; has-testing-info removed

#4 @gautam23
6 months ago

I was able to reproduce this issue as per the steps provided by @SirLouen

Steps Taken:

Exactly as described by OP in ticket:

  1. Installed the said plugin: https://raw.githubusercontent.com/SirLouen/wp-query-tester/refs/tags/1.0.1/wp-query-tester.php
  1. Created a second username called "User 2"
  1. Created some posts in this order:
    • First post, made sticky
    • Second not sticky post. Called it exactly, "Not Sticky 1", with slug "not-sticky-1".
    • Third, made sticky post
    • Fourth not sticky post
    • Fifth a sticky post, with "User 2" as author
    • Sixth, not sticky with "User 2" as author
    • Created another post called "Post List" and added the short code [wp_query_tester] in it

Result:

Able to reproduce the issue.

Screenshot:

https://i.ibb.co/KjYfpYvV/Screenshot-2025-06-04-at-8-08-12-PM.png

PS:
If I add 'ignore_sticky_posts' => 1 to both the queries where the result is "unexpected", it works as "expected". Notably, the docs(https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters) mention that when using post__in, the sticky posts are prepended to the query results, whether you want it or not. But no such thing is written for post_name__in or author__in.

Note: See TracTickets for help on using tickets.