From 898fd19d0ef8d654a8473a3dce9550882420637e Mon Sep 17 00:00:00 2001 From: Andrew 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: https://develop.svn.wordpress.org/trunk@21169 602fd350-edb4-49c9-b593-d223f7449a82 --- 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