WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 3 months ago

Last modified 3 months ago

#49685 closed defect (bug) (fixed)

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 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.


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

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

#2 @obliviousharmony
6 months ago

  • Keywords has-patch has-unit-tests added

#3 @SergeyBiryukov
6 months ago

  • Milestone changed from Awaiting Review to 5.5

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


6 months ago

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


5 months ago

#6 @obliviousharmony
3 months 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.


3 months ago

#8 @SergeyBiryukov
3 months ago

  • Keywords commit added

#9 @whyisjake
3 months 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.