Make WordPress Core

Opened 3 months ago

Last modified 2 months ago

#49685 assigned defect (bug)

Cached wp_count_posts() result may not contain all statuses

Reported by: obliviousharmony Owned by: obliviousharmony
Milestone: 5.5 Priority: normal
Severity: minor Version: 5.4
Component: Posts, Post Types Keywords: has-patch has-unit-tests
Focuses: Cc:



The wp_count_posts() function returns all of the post counts keyed by the status. This result is cached and served on subsequent calls. If a post status has no posts and has not been registered when the function is called, the cached response will contain no entry for the status. This leads to problems when iterating using get_post_stati() as not all of the post statuses will have a count.

Change History (5)

This ticket was mentioned in PR #199 on WordPress/wordpress-develop by ObliviousHarmony.

3 months ago

When wp_count_posts() is cached, it does so with all statuses defaulted to 0. The problem is however, if this is called before all plugins have registered their desired statuses, they won't have that default.

Related Issues:

Trac ticket: https://core.trac.wordpress.org/ticket/49685

#2 @obliviousharmony
3 months ago

  • Keywords has-patch has-unit-tests added

#3 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 5.5

This ticket was mentioned in Slack in #core by sergey. View the logs.

3 months ago

This ticket was mentioned in Slack in #core by obliviousharmony. View the logs.

2 months ago

Note: See TracTickets for help on using tickets.