WordPress.org

Ready to get started?Download WordPress

Forums

Custom Permalinks
404 Error - potentially caused by revisions (6 posts)

  1. eserrano
    Member
    Posted 1 year ago #

    I think I've found some kind of issue, and while I'm not sure about the root causes, this workaround seems to fix it.

    First, I have to say I'm using this plugin on other installations with other (similar) plugin configurations and it works great.

    But for some reason, during my last installation I noticed that some posts and pages would lead to 404 errors. I analyzed the kind of posts and pages that were causing the issue, and all of them seemed to have a revision saved. I could see this revision listed in Tools > Custom Permalinks with the same custom permalink as the defined for the original post.

    Posts / pages with no revisions or custom permalinks defined were working perfectly. So I decided to erase all revisions (using Better Delete Revision) and give it a try again. After all revisions were erased, the custom permalinks worked perfectly once more!

    Again, I don't know what this is happening on this particular installation (it works great on other ones) but removing the revisions seemed to fix the problem.

    However, this was just a quick workaround. I needed to keep revisions working, as autosaves and updates were still generating new revisions and thus breaking the custom permalinks, leading again to 404 errors.

    So my guess is that the custom permalinks plugin was querying the database to find out the original URL related to that post, and returning the URL of a post revision, which wouldn't work.

    I tried removing potential matches from revisions that seemed to break how this was working by editing the original plugin code. After line 164 of the custom permalinks plugin php file, inside custom_permalinks_request, I just added this code to the query:

    " post_type NOT IN ('revision') AND ".

    Filtering out results from "revisions" seemed to fix it. And all the 404 errors stopped appearing. Does all this make any sense?

    http://wordpress.org/extend/plugins/custom-permalinks/

  2. hackos
    Member
    Posted 1 year ago #

    Esserrano, you are one supremely cool guy. Saved my bacon. Thank you.

    Like you, no idea why this problem suddenly emerged but it did and this fixed it.

  3. eserrano
    Member
    Posted 1 year ago #

    I'm glad it helped!

    I still don't know why this happens only in some of my installations, but if I didn't add that line of code, it would keep failing.

    So I don't know the causes, but I know what happens if you don't filter out revisions in that query.

    The post_type retrieved could be revision (not post or page). So if we are given data from a revision, we would always end up inside the function:

    custom_permalinks_original_post_link($post_id)

    Continuing with the execution, right after the filters are removed, and precisely in line 666, we would execute:

    get_permalink( $post_id )

    And since $post_id is the ID of the revision (not the ID of the original post or page) tracing the output would always return something like:

    [ID]-revision

    Which isn't what we expected and leads to a 404 error. However, if we used the ID of the original post or page when calling get_permalink, the function would return something like:

    my-custom-permalink

    This is what we expected, and it works flawlessly. That explains why filtering out revisions in the query performed at line 164 solves this issue.

  4. mbohea
    Member
    Posted 1 year ago #

    Bump.

    This is causing major issues for me and hopefully the plugin developer can update the plugin accordingly.

    Good work eserrano.

  5. FranH
    Member
    Posted 1 year ago #

    +1
    confirmed the problem

  6. Martin
    Member
    Posted 1 year ago #

    Great spotting @eserrano

    Not that I saw any errors of the kind you mention but this one site that is only really different to others, is running this plugin and has only recently been displaying some weird stuff like 500 errors only on the Admin Front Page.

    There also seems to be some deprecated code about User Roles in the plugin as well. Sounds like the plugin needs a new maintainer since the author appears to be unable to devote time to it.

    Thanks again for the catch and it also seems like the site is running/loading a little faster too.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic