#49685 closed defect (bug) (fixed)
Cached wp_count_posts() result may not contain all statuses
Reported by: |
|
Owned by: |
|
---|---|---|---|
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
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
This ticket was mentioned in Slack in #core by david.baumwald. View the logs.
5 years ago
whyisjake commented on PR #199:
5 years ago
#10
Closing, merged here: https://core.trac.wordpress.org/changeset/48497
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