From 1a08c043717dda14c9860e08c16a007d68a39ca4 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Tue, 29 May 2007 04:54:45 +0000 Subject: [PATCH] switch to term_id and name for category sorting. see #4189. sort by term_id for category permalinks, by name for get_the_category(). fixes #4335 for trunk. Props Erik Barzeski for the find. git-svn-id: https://develop.svn.wordpress.org/trunk@5590 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/category-template.php | 15 ++++++++++++--- wp-includes/link-template.php | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index cc419a48a0..0b84ed92b1 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -69,15 +69,24 @@ function get_the_category($id = false) { $categories = get_object_terms($id, 'category'); if ( !empty($categories) ) - usort($categories, '_get_the_category_usort'); + usort($categories, '_usort_terms_by_name'); else $categories = array(); return $categories; } -function _get_the_category_usort($a, $b) { - return strcmp($a->category_name, $b->category_name); +function _usort_terms_by_name($a, $b) { + return strcmp($a->name, $b->name); +} + +function _usort_terms_by_ID($a, $b) { + if ( $a->term_id > $b->term_id ) + return 1; + elseif ( $a->term_id < $b->term_id ) + return -1; + else + return 0; } function get_the_category_by_ID($cat_ID) { diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 2c3912b811..4735696425 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -73,6 +73,8 @@ function get_permalink($id = 0) { $category = ''; if (strpos($permalink, '%category%') !== false) { $cats = get_the_category($post->ID); + if ( $cats ) + usort($cats, '_usort_terms_by_ID'); // order by ID $category = $cats[0]->slug; if ( $parent=$cats[0]->parent ) $category = get_category_parents($parent, FALSE, '/', TRUE) . $category;