Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#49685 closed defect (bug) (fixed)

Cached wp_count_posts() result may not contain all statuses

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

Description

Hello,

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 (10)

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


5 years ago
#1

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:
woocommerce/woocommerce#25949

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

#2 @obliviousharmony
5 years ago

  • Keywords has-patch has-unit-tests added

#3 @SergeyBiryukov
5 years ago

  • Milestone changed from Awaiting Review to 5.5

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


5 years ago

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


5 years ago

#6 @obliviousharmony
5 years ago

Could you take a look at this one too @desrosj?

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


5 years ago

#8 @SergeyBiryukov
5 years ago

  • Keywords commit added

#9 @whyisjake
5 years ago

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

In 48497:

Posts, Post Types: Ensure that all post stati are countable in wp_count_posts.

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.

Fixes #49685.

Props obliviousharmony, SergeyBiryukov.

Note: See TracTickets for help on using tickets.