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
This commit is contained in:
Andrew Nacin 2012-06-28 20:28:57 +00:00
parent b74c0203d9
commit 898fd19d0e
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