Opened 15 years ago
Last modified 8 months ago
#10663 new defect (bug)
Category name handling wrong function is_category
Reported by: | Azaroth | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.8.4 |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
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 (3)
Change History (16)
#1
@
15 years ago
- Component changed from General to Template
- Keywords needs-patch added
- Milestone set to 2.9
#3
@
15 years ago
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.
#5
@
15 years ago
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.
#6
@
14 years ago
- Cc wojtek.szkutnik@… added
- Keywords has-patch needs-testing gsoc added
Correct me if I'm wrong, this should work :)
#7
@
11 years ago
- Component changed from Template to Query
- Keywords close added
This feels like something we probably should not try to do. It's fairly ambiguous in nature. Even if we have a clear way of doing it internally, it's not exactly straightforward to use it. It's a cheap function, feels nicer to call it a few times.
#8
follow-up:
↓ 12
@
11 years ago
- Keywords needs-unit-tests added; dev-feedback needs-testing gsoc close removed
- Milestone changed from Future Release to 4.0
10663.diff - this bug sucks, we should fix it. All of my new assertions pass except for $this->assertTrue( is_category( "$cat_id" ) );
- strangely does work for is_tag()
, which we should also attack here.
This ticket was mentioned in IRC in #wordpress-dev by DrewAPicture. View the logs.
10 years ago
#12
in reply to:
↑ 8
@
10 years ago
- Keywords commit removed
- Milestone changed from 4.0 to Future Release
Sounds like there's some stuff left to do here:
Replying to wonderboymusic:
10663.diff - this bug sucks, we should fix it. All of my new assertions pass except for
$this->assertTrue( is_category( "$cat_id" ) );
- strangely does work foris_tag()
, which we should also attack here.
Punting.
No patch.