#38843 closed enhancement (fixed)
Add filter for post statuses in _update_post_term_count()
Reported by: | GunGeekATX | Owned by: | adamsilverstein |
---|---|---|---|
Milestone: | 5.7 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Taxonomy | Keywords: | has-patch has-unit-tests commit has-dev-note |
Focuses: | Cc: |
Description
_update_post_term_count()
is hard-coded to only use the 'publish' status when updating the post count for a term. The lack of a filter here does not allow the term count to include other post statuses (or custom post statuses) in situations where the user would like the term count to reflect the other statuses.
Example of using proposed patch to allow 'future' status to be included in Category term count.
add_filter( 'update_post_term_count_statuses', function( $post_statuses, $taxonomy ) { // Allow future statuses to be counted for Category post count. if ( 'category' === $taxonomy->name ) { $post_statuses[] = 'future'; } return $post_statuses; }, 10, 2 );
Attachments (7)
Change History (28)
#2
@
6 years ago
- Keywords needs-unit-tests added
- Owner set to adamsilverstein
- Status changed from new to assigned
This ticket was mentioned in Slack in #core by davecpage. View the logs.
6 years ago
#5
@
4 years ago
In 38843.diff: Updated patch and added test coverage for new filter.
This ticket was mentioned in PR #838 on WordPress/wordpress-develop by adamsilverstein.
4 years ago
#8
Trac ticket:
#9
@
4 years ago
Sorry my comment with the modified diff was a little cryptic.
The SQL statement is rather long and contained 2 occurrences of "= 'publish'" (one for posts and the other for attachments).
The previous fix addressed only the first one.
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#11
@
4 years ago
- Keywords needs-dev-note added
Adds a new filter. Noting needs inclusion into the misc dev note.
#12
@
4 years ago
@hellofromTonya @SergeyBiryukov patch and unit tests refreshed as per today's bug scrub.
#13
@
4 years ago
- Keywords commit added
Attached gif shows the changes work. Here's the hooked callback I used in a must-use file:
<?php add_filter( 'update_post_term_count_statuses', function ( $statuses, $taxonomy ) { if ( 'category' === $taxonomy->name ) { $statuses[] = 'draft'; $statuses[] = 'future'; $statuses[] = 'pending'; } return $statuses; }, 10, 2 );
Marking this ticket ready as a commit
candidate.
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#16
@
4 years ago
@param int $taxonomy Current taxonomy object.
should be a WP_Taxonomy
right? It'd be nice to get this in a PR.
hellofromtonya commented on PR #838:
4 years ago
#19
Closed with changeset https://core.trac.wordpress.org/changeset/50169
Proposed patch with filter