Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#52007 closed defect (bug) (fixed)

sticky_posts somehow ends up with duplicate IDs and unstickying only removes one at a time

Reported by: archon810's profile archon810 Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 5.7 Priority: normal
Severity: normal Version: 5.5.3
Component: Posts, Post Types Keywords: has-patch has-unit-tests commit
Focuses: Cc:


Hi all,

Somehow we ran into this bug on production where the sticky_posts array ended up with duplicate IDs that were stickied, and unstickying only removed the same ID one at a time instead of all of them at once, so unstickying kept the post stickied until it was unstickied enough times to clear the array.

For example, this is how I found sticky_posts:


Note that 725382 is duplicated. Unstickying once did this:


How we got to the duplicate ID state, I cannot say (perhaps that's a separate bug), but solution here is to not exit the loop when the ID is reached and removed and instead keep going till the end.

Change History (13)

#1 @SergeyBiryukov
3 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.7

Thanks for the ticket! It seems like we should run array_unique() on the sticky_posts option at some point here.

#2 @archon810
3 years ago

This just happened again. The fix should be really simple, can we give this one a kick please?

This ticket was mentioned in PR #981 on WordPress/wordpress-develop by Rahmon.

3 years ago

  • Keywords has-patch has-unit-tests added; needs-patch removed

This change tries to prevent duplicate post IDs in the sticky_posts option.

Trac ticket:

Rahmon commented on PR #981:

3 years ago

Hi @peterwilsoncc

Thank you for your review. I'll take a look.

Rahmon commented on PR #981:

3 years ago

@peterwilsoncc I've split up the assertions a little. :grimacing:

peterwilsoncc commented on PR #981:

3 years ago

These tests look way more focused, thank you.

It might be good to use a data provider but I can push those as they are a little fiddly.

Code changes and tests look good to me.

peterwilsoncc commented on PR #981:

3 years ago

@Rahmon I've pushed some minor changes to the tests in

  • Used a data provider where possible.
  • Added tests to make sure the database isn't updated unnecessarily
  • Added docblocks too

peterwilsoncc commented on PR #981:

3 years ago

@Rahmon Oh, meant to ask: what is your username so i can give props on the ticket?

#9 @peterwilsoncc
3 years ago

  • Keywords commit added
  • Owner set to peterwilsoncc
  • Status changed from new to assigned

Reckon this is good to go.

Rahmon commented on PR #981:

3 years ago

@peterwilsoncc my username is rahmohn (

#11 @peterwilsoncc
3 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 50380:

Posts/Post Types: Prevent duplicates in sticky posts option.

In unstick_post() if a post ID is duplicated in the sticky_posts option remove all instances.

In both stick_post() and unstick_post() check for duplicate IDs already stored in the sticky_post option and remove them if the option is updated.

Props rahmohn, archon810.
Fixes #52007.

#13 @SergeyBiryukov
3 years ago

In 50384:

Tests: Rename stick_post() and unstick_post() tests for a bit more clarity.

Add missing DocBlock for test_unstick_post_updates_option().

Follow-up to [50380].

See #52007.

Note: See TracTickets for help on using tickets.