Opened 4 years ago
Last modified 3 years ago
#10663 new defect (bug)
Category name handling wrong function is_category
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Template | Version: | 2.8.4 |
| Severity: | normal | Keywords: | dev-feedback has-patch needs-testing gsoc |
| Cc: | wojtek.szkutnik@… |
Description
When putting numbers in front of the category names, Wordpress uses them as basis for the function is_category which leads to problems with e.g. plugins using this function.
Example:
- 3 Categories: "News" (id 1), "1st Release" (id 2), "2nd Release" (id 3)
- Trying to check the category with is_category(1) works for news, but also returns true for the category "1st Release"
- Trying to check the category with is_category(2) returns true for both, "1st Release" and "2nd Release"
This behaviour is not expected. It might be interesting when you explicitely give the category numbers as names (e.g. "1", "2", "3"). Changing the in_array function to a simple equal comparison makes everything work as expected.
Attachments (1)
Change History (7)
- Component changed from General to Template
- Keywords needs-patch added
- Milestone set to 2.9
Changing the in_array function to a simple equal comparison makes everything work as expected.
The problem is that you have to also be able to do this:
is_category(array(1, 2))
is_category(array('cat-slug-a', 'cat-slug-b'))
is_category(array('Cat Name A', 'Cat Name B'))
is_category(array(1, 'cat-slug-a', 'Cat Name A'))
Of course, this can cause all sorts of ambiguities.
Perhaps the fix would be to do a strict comparison
in_array( $cat_obj->term_id, $category, true )
although checking for category ID and using a string would then fail: is_category(3) will work, is_category('3') will not.
wojtek.szkutnik — 3 years ago
comment:6
wojtek.szkutnik — 3 years ago
- Cc wojtek.szkutnik@… added
- Keywords has-patch needs-testing gsoc added
Correct me if I'm wrong, this should work :)

No patch.