WordPress.org

Make WordPress Core

Opened 6 years ago

Last modified 3 weeks ago

#14490 reopened defect (bug)

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

Reported by: iamronen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 3.1
Component: Taxonomy Keywords: reporter-feedback
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 (13)

#1 @blepoxp
6 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
6 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
6 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.

Version 1, edited 6 years ago by MikeNGarrett (previous) (next) (diff)

#4 follow-up: @logiclord
6 years ago

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

Works in my case too

#5 in reply to: ↑ 3 @hakre
6 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
6 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
6 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
6 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 6 years ago by logiclord (previous) (diff)

#9 @ocean90
6 years ago

  • Milestone set to Awaiting Review

#10 @SergeyBiryukov
4 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
3 months 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
7 weeks 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 7 weeks ago by jackreichert (previous) (diff)

#13 @netweb
3 weeks ago

  • Milestone set to Awaiting Review

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

Note: See TracTickets for help on using tickets.