Opened 3 years ago
Closed 5 months ago
#14490 closed defect (bug) (invalid)
function "get cat ID" fails if category name has an apostrophe
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Taxonomy | Version: | 3.1 |
| Severity: | minor | Keywords: | reporter-feedback |
| Cc: | MikeNGarrett |
Description
the function get_cat_ID() fails if the category name has an apostrophe in it (maybe other characters as well??).
Change History (10)
- Component changed from General to Taxonomy
- Keywords reporter-feedback added; 2nd-opinion removed
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed
Appears to work as expected for me too.
Closing as worksforme. Re-open with specific steps to duplicate if you can re-create it.
comment:3
follow-up:
↓ 5
MikeNGarrett — 2 years ago
- Cc MikeNGarrett added
- Resolution worksforme deleted
- Severity changed from normal to minor
- Status changed from closed to reopened
- Version set to 3.1
get_cat_ID doesn't handle fancy quotes and apostrophe's, eg. “ ‘ ” ’
On a mac, hold option and press [ and ], then hold shift and press the same buttons. I can confirm this is the reason it's not working. I don't know if other special characters are being handled.
More details:
I tried to change the category name to use a tick mark, ' , instead, but the saved value was always considered a smart fancy quote ’. Seems like the problem stems from the category, not get_cat_id(). Both should be modified to handle fancy quotes.
I just realized that single_cat_title() should only be used for displaying the current category on a page. That's probably where the fancy quotes come from. I've seen this function being used to retrieve the name of the category page, which is then used to retrieve the category id. The better process is to do the following:
global $wp_query;
if(is_category() || is_single()){
$cid = get_query_var('cat');
}
Or you could get the category slug from the url and work that way. Neither seems ideal unless I'm missing something.
- Resolution set to fixed
- Status changed from reopened to closed
Works in my case too
- Keywords close removed
Replying to MikeNGarrett:
get_cat_ID doesn't handle fancy quotes and apostrophe's, eg. “ ‘ ” ’
On a mac, hold option and press [ and ], then hold shift and press the same buttons. I can confirm this is the reason it's not working. I don't know if other special characters are being handled.
Can you provide the unicode specification of the "fancy" characters you're referring to? Reproducing your case with so little information is hard to do.
For example, I don't have an apple computer at hand so I can not even reproduce what you write.
If you can provide a formal specification of the characters you're referring to, feel free to reopen the ticket.
Replying to logiclord:
Works in my case too
Can you provide a formal specification about which characters MikeNGarrett was speaking about?
- Resolution fixed deleted
- Status changed from closed to reopened
I think i understood what is your issue
when you create a category say Test'Cat it is shown as Test’Cat but actually its Test'Cat
and when you use get_cat_ID( "Test’Cat" ) it doesn't give a matching ID so do not go by ’ use ' that you typed while creating that category.
comment:10
SergeyBiryukov — 5 months ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from reopened to closed
comment:8 sounds like a valid explanation. You can see the original (unformatted) category name on Edit Category screen.

I could not reproduce this with either of the following: