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:
parent
416ac97d43
commit
5d5c5df4ae
@ -122,8 +122,10 @@ function get_permalink($id = 0, $leavename = false) {
|
|||||||
$cats = get_the_category($post->ID);
|
$cats = get_the_category($post->ID);
|
||||||
if ( $cats ) {
|
if ( $cats ) {
|
||||||
usort($cats, '_usort_terms_by_ID'); // order by ID
|
usort($cats, '_usort_terms_by_ID'); // order by ID
|
||||||
$category = $cats[0]->slug;
|
$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
|
||||||
if ( $parent = $cats[0]->parent )
|
$category_object = get_term( $category_object, 'category' );
|
||||||
|
$category = $category_object->slug;
|
||||||
|
if ( $parent = $category_object->parent )
|
||||||
$category = get_category_parents($parent, false, '/', true) . $category;
|
$category = get_category_parents($parent, false, '/', true) . $category;
|
||||||
}
|
}
|
||||||
// show default category in permalinks, without
|
// show default category in permalinks, without
|
||||||
|
Loading…
Reference in New Issue
Block a user