• I have a CPT of ‘webinars’. I use that to create posts for a category called ‘Upcoming Webinars’ that lives on the page /Upcoming-Webinar. I use that category for posts until the event expires (using the Post Expirator plug in). When the event expires (one hour after start time) it gets moved to draft and an email is fired off to the author notifying them their event has been moved to ‘draft’ status and some things they need to do. The major thing they need to do is change the category from ‘Upcoming-Webinars’ to ‘Archived-Webinars’.

    Once that is done, the post is now visible on the /Upcoming-Webinars page. All this works as expected.

    The issue is this: When the post is moved from /Upcoming-Webinars to /Archived-Webinars, the permalink still has the category /upcoming-webinars. EX:
    Upcoming-Webinars (where it starts) url: http://dev.com/Upcoming-Webinars/page-title/
    then it expiers and is moved to /Archived-Webinars/ but the link is still http://dev.com/Upcoming-Webinars/page-title/ and not http://dev.com/Archived-Webinars/page-title/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Where are you seeing these erroneous links? The archive page for the category? Look for the code responsible for the permalink output. If it’s the_permalink(), the output can be filtered to generate the proper permalink. For any other code, what to do depends on the the code used.

    The “normal” permalink for a post is just the domain plus title slug, categories usually do not factor in. If the category is being inserted by a filter used by the_permalink(), then that filter code probably needs to be fixed. If you cannot locate the code responsible, you can still override the result by adding another filter that fires later in the process. Not optimal, but it’ll work if you cannot determine the proper fix.

    Thread Starter DirtyBirdDesign

    (@dirtybirddesign)

    Any leads as to how to filter the permalink? I think that it just boils down to the permalink not updating (because its a permalink), when you change a post’s category. Is this possible?

    Moderator bcworkz

    (@bcworkz)

    Here’s an idea:

    add_filter('the_permalink', 'dbd_fix_permalink', 99, 2 );
    function dbd_fix_permalink( $link, $post ) {
       //insert code to build new permalink for $post here
       return $link;
    }

    Nothing in WP is permanent 🙂 Permalinks are built dynamically based on the permastruct defined in the settings. The post slug is the closest thing to “permanent”, yet that too can be changed at will. The filter suggested is really just a sloppy patch, it’d be better to fix the root cause.

    When the permastruct contains %category%, the current category slug should get substituted for that placeholder when the permalink is built. If there are multiple categories, the term with the lowest ID is used. It doesn’t sound like that is happening, I’m guessing some other code from a theme or plugin is overriding the normal behavior.

    You can test this by temporarily switching to one of the default themes and deactivating all plugins. The permalinks should then reflect the current category. Reinstate your theme and plugins one by one, testing after each time. When the permalinks fail to reflect the current category, the last activated code is the culprit.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Changing post category and update permalink’ is closed to new replies.