New post_link_category causes admin problems (2 posts)

  1. spykawg
    Posted 2 years ago #

    Hi all,

    I've noticed that the new addition of the post_link_category filter in link-template.php seems to be causing backend problems.

    The issue occurs when the category slug isn't derived from the category name.

    For example, Category name is "My Favourite Things" but the category slug is just "things" (as opposed to my-favourite-things)

    As a result, the permalinks, and other links in the admin panel return the wrong URLs.

    You'd expect a post in the above category to have the URL of site.com/things/post-slug

    Instead, the admin panel shows it as site.com/my-favourite-things/post-slug.

    Similarly, the category links on the List post page link to edit.php?category_name=my-favourite-things rather than edit.php?category_name=things

    The first link naturally returns an error, as no such category exists with that slug in the database.

    The problem appears to be limited to the backend, all links on the front end website work as expected.

    As a temporary fix, I've replaced:

    usort($cats, '_usort_terms_by_ID'); // order by ID
    				$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;

    in link-template with:

    usort($cats, '_usort_terms_by_ID'); // order by ID
    				$category = $cats[0]->slug;
    				if ( $parent = $cats[0]->parent )
    					$category = get_category_parents($parent, false, '/', true) . $category;

    from the 3.4.2. This fixes the issue.

    I'm not a PHP expert so I'm not sure what specifically is causing the issue other than the change itself, which is also why I didn't post a bug report.

  2. spykawg
    Posted 1 year ago #

    I've noticed this issue still exists in 3.6.1, can anyone confirm that, or is it just an issue with my specific install?

Topic Closed

This topic has been closed to new replies.

About this Topic