WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 16 months ago

#14490 closed defect (bug) (invalid)

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
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 (10)

comment:1 blepoxp4 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

comment:2 dd324 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.

comment:3 follow-up: MikeNGarrett3 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.

Last edited 3 years ago by MikeNGarrett (previous) (diff)

comment:4 follow-up: logiclord3 years ago

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

Works in my case too

comment:5 in reply to: ↑ 3 hakre3 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.

comment:6 in reply to: ↑ 4 ; follow-up: hakre3 years ago

Replying to logiclord:

Works in my case too

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

comment:7 in reply to: ↑ 6 logiclord3 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

comment:8 logiclord3 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 3 years ago by logiclord (previous) (diff)

comment:9 ocean903 years ago

  • Milestone set to Awaiting Review

comment:10 SergeyBiryukov16 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.

Note: See TracTickets for help on using tickets.