Make WordPress Core

Opened 4 years ago

Last modified 2 years ago

#38843 assigned enhancement

Add filter for post statuses in _update_post_term_count()

Reported by: GunGeekATX Owned by: adamsilverstein
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: Taxonomy Keywords: has-patch needs-unit-tests
Focuses: Cc:


_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 (1)

38843.patch (1.9 KB) - added by GunGeekATX 4 years ago.
Proposed patch with filter

Download all attachments as: .zip

Change History (5)

4 years ago

Proposed patch with filter

#1 @GunGeekATX
4 years ago

  • Keywords has-patch added

#2 @adamsilverstein
2 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.

2 years ago

Note: See TracTickets for help on using tickets.