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
This commit is contained in:
nacin 2012-06-28 20:28:57 +00:00
parent 416ac97d43
commit 5d5c5df4ae
1 changed files with 4 additions and 2 deletions

View File

@ -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