Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#15231 closed defect (bug) (duplicate)

get_the_category() used strcmp() which is case sensitive

Reported by: joehoyle's profile joehoyle Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords:
Focuses: Cc:


I recently ran into an issue with get_the_category() returning the array of categories ordered by Name (which is does by default). However, this will return different results than wp_get_object_terms(), because wp_get_object_terms() used an SQL ORDER BY which (correct me if I am wrong) will do a case insensitive string compare, whereas using strcmp() is case sensitive, so any categories starting in a lowercase letter will be but _after_ all capitalized names.


$terms = wp_get_object_terms( $id );
// array( 'Apple, 'iPod', Microsoft' )

$cats = get_the_category( $id );
// array( 'Apple', 'Microsoft', 'iPod' )

Which seems counterintuitive. Should this be fixed?

Change History (3)

#1 @nacin
14 years ago

So... transition to strcasecmp()?

#2 @joehoyle
14 years ago

Well, we don't need to use _usort_terms_by_name(), why not just pass 'orderby' => 'name' to wp_get_object_terms() in get_the_category()?

#3 @scribu
14 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

This was fixed by #15407

Note: See TracTickets for help on using tickets.