WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 2 years ago

#15919 closed defect (bug) (fixed)

wp_count_terms() hide_empty not working

Reported by: zeo Owned by: markjaquith
Milestone: 3.7 Priority: high
Severity: major Version:
Component: Taxonomy Keywords: has-patch 3.7-early
Focuses: Cc:

Description

For tax category, wp_count_terms( 'category', array( 'hide_empty' => true ) ) returns all category and doesn't hide category with post count 0. Instead need to use wp_count_terms( 'category', array( 'hide_empty' => true, 'hierarchical' => false ) ).

Since hide_empty=false is the default args, wp_count_terms() should set hierarchical=false by default too.

Attachments (4)

15919.diff (353 bytes) - added by zeo 5 years ago.
15919.002.diff (392 bytes) - added by markjaquith 5 years ago.
patch at a deeper level
15919.2.diff (392 bytes) - added by wonderboymusic 3 years ago.
15919_3.diff (446 bytes) - added by faishal 2 years ago.
updated patch

Download all attachments as: .zip

Change History (16)

@zeo5 years ago

comment:1 @markjaquith5 years ago

  • Milestone changed from Awaiting Review to 3.1
  • Owner set to markjaquith
  • Status changed from new to accepted

Bug reproduced. Patch fixes it.

Last edited 5 years ago by markjaquith (previous) (diff)

comment:2 @scribu5 years ago

Is this a regression?

comment:3 @dd325 years ago

  • Component changed from General to Taxonomy

comment:4 @markjaquith5 years ago

  • Keywords 3.2-early added
  • Milestone changed from 3.1 to Future Release
  • Priority changed from normal to high
  • Severity changed from normal to major

This is not a regression from 3.0, so I'm going to do it 3.2-early.

@markjaquith5 years ago

patch at a deeper level

comment:5 @SergeyBiryukov4 years ago

Closed #19340 as a duplicate.

@wonderboymusic3 years ago

comment:6 @wonderboymusic3 years ago

  • Milestone changed from Future Release to 3.6

Refreshed against trunk just so the line numbers match - this is from the class of 3.2-early

@faishal2 years ago

updated patch

comment:7 @faishal2 years ago

  • Keywords 3.2-early removed

comment:8 @SergeyBiryukov2 years ago

Generally, a refresh is only needed when the patch no longer applies cleanly.

Line numbers may be off, but as long as the content is the same, the patch should still apply cleanly. 15919.2.diff is still fine.

Also, when copying code directly from Trac, make sure to remove trailing whitespace.

Version 0, edited 2 years ago by SergeyBiryukov (next)

comment:9 @nacin2 years ago

  • Keywords 3.7-early added
  • Milestone changed from 3.6 to Future Release

comment:10 @wonderboymusic2 years ago

  • Milestone changed from Future Release to 3.7

comment:11 @wonderboymusic2 years ago

these are all marked 3.7-early

comment:12 @wonderboymusic2 years ago

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

In 25551:

Ensure that terms with a post count of 0 are not returned in wp_count_terms() when hide_empty => true. Adds unit test which ensures that wp_count_terms() returns 0.

Props markjaquith.
Fixes #15919.

Note: See TracTickets for help on using tickets.