WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#9059 closed defect (bug) (wontfix)

category with name '0' gets ignored

Reported by: noonoo Owned by:
Milestone: Priority: low
Severity: minor Version: 2.7
Component: Optimization Keywords: needs-patch potential-wontfix
Focuses: Cc:

Description

I have a category called 0 (zero) for all posts starting with 0, <?php single_cat_title(); ?> doesnt show 0 when inside that category, it works fine for all the other numbered categorys and all individual lettered categorys also work fine its just 0 thats giving me problems.

If i add something before or after the 0 it will then show but shouldnt it work ok with just 0?

Thanks in advance

Attachments (1)

9059.patch (582 bytes) - added by Viper007Bond 5 years ago.
Simple but effective workaround

Download all attachments as: .zip

Change History (12)

comment:1 Viper007Bond5 years ago

  • Component changed from Themes to Template
  • Keywords needs-patch added; single_cat_title numbered category 0 removed
  • Owner set to anonymous

The problem comes from the usage of if ( !empty($variable) ).

And actually there's two problems going on here. Viewing the archive for a category with the stub of 0 doesn't load the archive.php template -- it uses index.php. I've made a separate ticket for that though: #9352

Viper007Bond5 years ago

Simple but effective workaround

comment:2 Denis-de-Bernardy5 years ago

  • Component changed from Template to Optimization
  • Keywords dev-feedback added
  • Milestone set to 2.8
  • Summary changed from single_cat_title wont show category called 0 to Why is WP using empty()?

On a more general note, why in the bloody hell is empty() used throughout WP.

I did a few tests on my end while wondering whether empty() or casting to boolean works fastest, and the latter beats the former by a landslide.

if ( !empty($foo) )
  ...

is slower than:

if ( !$foo )
  ...

comment:3 ryan5 years ago

Because empty() will avoid not set warnings, I reckon.

comment:4 mrmist5 years ago

  • Keywords dev-feedback removed

Yep, the !empty avoids the PHP Notice: Undefined variable: foo

Back to the original patch - the change doesn't work for me. But then on IIS the

index.php/category/0/

Displays just like the front page, its almost as if the cat is not redirected at all, so the fact that the category name isn't displayed is the least of the issue.

Removing dev-feedback since Ryan replied.

comment:5 simonwheatley5 years ago

  • Keywords has-patch added; needs-patch removed

Changed keyword from needs-patch to has-patch. Did not test patch.

comment:6 Denis-de-Bernardy5 years ago

  • Keywords needs-patch added; has-patch removed
  • Summary changed from Why is WP using empty()? to category with name '0' gets ignored

patch is no good. as highlighted by mist, the real issue is that such a category gets ignored entirely by WP, due to the fact that, well... empty('0') returns true.

wontfix imo

comment:9 Denis-de-Bernardy5 years ago

  • Milestone changed from 2.8 to 2.9

moving to 2.9, from lack of valid patch

comment:10 hakre5 years ago

  • Keywords potential-wontfix added

-1My Opinion: You will never get this patched. There are way tooo much IFs verywhere that check for false or empty and this category name. I just would comment "forget it".

comment:11 Denis-de-Bernardy5 years ago

  • Milestone 2.9 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

let's close this, then.

Note: See TracTickets for help on using tickets.