From 5d5c5df4aed68232f82618e15221488f320fdff6 Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 28 Jun 2012 20:28:57 +0000 Subject: [PATCH] Add a post_link_category filter to the permalink generation process. This allows a plugin to easily change which category gets represented in the URL. Previously, it went off the category with the smallest ID. props aaroncampbell fixes #18752 git-svn-id: http://core.svn.wordpress.org/trunk@21169 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index ae8a9f136c..df7bc741f6 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -122,8 +122,10 @@ function get_permalink($id = 0, $leavename = 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_object = apply_filters( 'post_link_category', $cats[0], $cats, $post ); + $category_object = get_term( $category_object, 'category' ); + $category = $category_object->slug; + if ( $parent = $category_object->parent ) $category = get_category_parents($parent, false, '/', true) . $category; } // show default category in permalinks, without