Make WordPress Core

Opened 14 years ago

Closed 6 years ago

Last modified 5 years ago

#14490 closed defect (bug) (worksforme)

function "get cat ID" fails if category name has an apostrophe

Reported by: iamronen's profile 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)

#1 @blepoxp
14 years ago

  • Keywords 2nd-opinion close added

I could not reproduce this with either of the following:

echo get_cat_ID( 'Test \'an apostrophe!' ); // echoed the correct category ID
echo get_cat_ID( "Test 'an apostrophe!" ); // echoed the correct category ID

#2 @dd32
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: @MikeNGarrett
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.

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.

Version 2, edited 14 years ago by MikeNGarrett (previous) (next) (diff)

#4 follow-up: @logiclord
14 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Works in my case too

#5 in reply to: ↑ 3 @hakre
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: @hakre
14 years ago

Replying to logiclord:

Works in my case too

Can you provide a formal specification about which characters MikeNGarrett was speaking about?

#7 in reply to: ↑ 6 @logiclord
14 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to hakre:

Replying to logiclord:

Works in my case too

Can you provide a formal specification about which characters MikeNGarrett was speaking about?

Suppose you have a category like foo'bar
then
get_cat_ID( "foo'bar" )
and
get_cat_ID( "foo\'bar" )

both seems to give correct category id

#8 @logiclord
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 &#8217 ’

Last edited 14 years ago by logiclord (previous) (diff)

#9 @ocean90
14 years ago

  • Milestone set to Awaiting Review

#10 @SergeyBiryukov
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 @sologne
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 @jackreichert
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.

Last edited 8 years ago by jackreichert (previous) (diff)

#13 @netweb
8 years ago

  • Milestone set to Awaiting Review

Moving reopened tickets without a milestone back to Awaiting Review for review

#16 @boonebgorges
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 as Foo’Bar on edit-tags.php, but this is just a formatting issue, and doesn't appear to affect querying by get_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 @MikeNGarrett
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.

Note: See TracTickets for help on using tickets.