#14490 closed defect (bug) (worksforme)
function "get cat ID" fails if category name has an apostrophe
Reported by: | iamronen | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 3.1 |
Component: | Taxonomy | Keywords: | reporter-feedback bulk-reopened |
Focuses: | Cc: |
Description
the function get_cat_ID() fails if the category name has an apostrophe in it (maybe other characters as well??).
Change History (15)
#2
@
14 years ago
- 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.
#3
follow-ups:
↓ 5
↓ 11
@
14 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.
#4
follow-up:
↓ 6
@
14 years ago
- Resolution set to fixed
- Status changed from reopened to closed
Works in my case too
#5
in reply to:
↑ 3
@
14 years ago
- 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.
#6
in reply to:
↑ 4
;
follow-up:
↓ 7
@
14 years ago
Replying to logiclord:
Works in my case too
Can you provide a formal specification about which characters MikeNGarrett was speaking about?
#8
@
14 years ago
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.
' equivalent to ' is being replaced by ’ ’
#10
@
12 years 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.
#11
in reply to:
↑ 3
@
8 years ago
- Resolution invalid deleted
- Status changed from closed to reopened
The comment 3 nails it.
Using single_cat_title to retrieve the category name ; and from that the cat_id ; is a common advice on the internet and it got me losing over an hour to fix the issue ; with the unintuitive get_query_var from comment 3.
Worse, there is not any kind of warning in the codex for single_cat_title that there may be such an issue.
This ticket has been closed ; but is there a good reason for get_cat_ID to NOT support "fancy quotes" ?
Also : seems related to #24354
#12
@
8 years ago
I'm wondering if this has to do with database collation. I was not able to reproduce this with database set to utf8mb4_unicode.
Categories I tried with:
echo get_cat_ID( "Jack’s cat" ); # using a single comma quotation mark
echo get_cat_ID( "Someone's cat" ); # using an apostrophe
echo get_cat_ID( "“I like spaghetti”" ); # using left and right double turned comma quotation mark
echo get_cat_ID( "˓ Modifier Letter Centered Left Half Ring" );
One thing I noticed was that the apostrophe was being translated to a single comma quotation mark here /wp-admin/edit-tags.php?taxonomy=category
. If I called it with get_cat_ID as a single comma quotation mark it came back 0 but if I called it as an apostrophe (what I had set it up as) it was fine.
#13
@
8 years ago
- Milestone set to Awaiting Review
Moving reopened tickets without a milestone back to Awaiting Review
for review
#16
@
6 years ago
- Keywords bulk-reopened added
- Resolution set to worksforme
- Status changed from reopened to closed
I'm unable to reproduce most of the issues described in this ticket.
- A category created as "Foo’Bar" is properly retrieved using
get_cat_ID( "Foo’Bar" )
- A category created as "Foo'Bar" is properly retrieved using
get_cat_ID( "Foo'Bar" )
- Both categories can be edited at wp-admin/term.php without changing the apostrophe formatting
- I can confirm that
Foo'Bar
is showing asFoo’Bar
on edit-tags.php, but this is just a formatting issue, and doesn't appear to affect querying byget_cat_ID()
One thing I can confirm is that single_cat_title()
is being run through wptexturize()
(ie, the return characters are HTML-encoded). But single_cat_title()
is meant for display, not for fetching data for the purposes of querying. If tutorials around the web say otherwise, then the tutorials are incorrect :) get_queried_object()
is the best way to identify the category on a term archive.
#17
@
6 years ago
Have to try and remember what was going on 8 years ago, but I'll give it a shot.
Handling taxonomy terms has greatly changed since 3.1, so the original issue is definitely no longer present. For example, get_cat_ID( 'Some’thing' );
and get_cat_ID( "Some'thing" );
now return their exact matches.
The only thing I could find that might cause issues is the category listing /wp-admin/edit-tags.php?taxonomy=category
does not differentiate these characters in displaying the term name. Tick marks, '
and "
, are converted to their fancy counterparts, ‘’
and “”
.
Screenshot: http://files.copper-note.com/mODwgNC
Why is this a problem?
Tick marks are used in measurement, eg 5'10"
while fancy quotes are used everywhere else, especially when “Someone says something”
.
WordPress converts ticks to fancy quotes nearly universally, so I don't see any reason to change in this context.
I could not reproduce this with either of the following: