Opened 23 months ago
Closed 23 months ago
#18009 closed defect (bug) (wontfix)
term_exists uses is_int so '0' does not equal 0 and so wp_set_object_terms will create 0
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 3.1 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
If setting object terms and one has not type casted string 0 to integer 0 then term_exists will see this as a category name and return false, the category 0 does not exists and wp_set_object_terms will create it.
It exists on line 1452 of taxonomy.php (http://core.trac.wordpress.org/browser/tags/3.2/wp-includes/taxonomy.php#L1452)
The fix is simple, switching is_int to is_numeric
Change History (3)
Replying to nacin:
That's actually proper behavior. The term API makes a distinct difference between a numeric string, treating it as a slug, and an integer, which it treats as an ID.
It seems rather counter-intuitive to the normal PHP workflow (ignoring types, that is) to make that sort of behavior built into the term API.
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
It is indeed confusing. A taxnomy API cleanup will happen some day. In the mean time this is what we have.

That's actually proper behavior. The term API makes a distinct difference between a numeric string, treating it as a slug, and an integer, which it treats as an ID.