• 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/

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.

    Thread Starter eserrano

    (@eserrano)

    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.

    Bump.

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

    Good work eserrano.

    +1
    confirmed the problem

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘404 Error – potentially caused by revisions’ is closed to new replies.