• Resolved askitbasket

    (@askitbasket)


    Hi there

    When I set up the custom post type “news and events”, I mistakenly added what I intended to be the custom rewrite ‘news-and-events’ (to replace underscores with hyphens) to the custom archive URL field instead of the custom rewrite slug.

    Now, when I try to fix this, I get a 404 error on any of the news and events single pages. I am stuck with an archive page which uses hyphens (news-and-events) while every single post has underscores.

    I have tried removing the custom archive URL text so it’s blank and putting ‘news-and-events’ in the custom rewrite slug field. I have tried resetting permalinks. I have tried various settings combinations but I just cannot crack it.

    Really grateful for any help.

    Here are my settings:

    Public
    True
    (Custom Post Type UI default: true) Whether or not posts of this type should be shown in the admin UI and is publicly queryable.

    Publicly Queryable
    True
    (default: true) Whether or not queries can be performed on the front end as part of parse_request()

    Show UI
    True
    (default: true) Whether or not to generate a default UI for managing this post type.

    Show in Nav Menus
    True
    (Custom Post Type UI default: true) Whether or not this post type is available for selection in navigation menus.

    Delete with user
    False
    (CPTUI default: false) Whether to delete posts of this type when deleting a user.

    Show in REST API
    True
    (Custom Post Type UI default: true) Whether or not to show this post type data in the WP REST API.

    REST API base slug
    Slug to use in REST API URLs.
    Slug to use in REST API URLs.
    REST API controller class
    (default: WP_REST_Posts_Controller) Custom controller to use instead of WP_REST_Posts_Controller.
    (default: WP_REST_Posts_Controller) Custom controller to use instead of WP_REST_Posts_Controller.
    Has Archive
    If left blank, the archive slug will default to the post type slug.

    True
    (default: false) Whether or not the post type will have a post type archive URL.

    news-and-events
    Slug to be used for archive URL.
    Exclude From Search
    False
    (default: false) Whether or not to exclude posts with this post type from front end search results.

    Capability Type
    post

    The post type to use for checking read, edit, and delete capabilities. A comma-separated second value can be used for plural version.

    Hierarchical
    False
    (default: false) Whether or not the post type can have parent-child relationships.

    Rewrite
    True
    (default: true) Whether or not WordPress should use rewrites for this post type.

    Custom Rewrite Slug
    (default: post type slug)
    (default: post type slug)
    Custom post type slug to use instead of the default.

    With Front
    True
    (default: true) Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/).

    Query Var
    True
    (default: true) Sets the query_var key for this post type.

    Custom Query Var Slug
    (default: post type slug) Query var needs to be true to use.
    (default: post type slug) Query var needs to be true to use.
    Custom query var slug to use instead of the default.

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Curious if something got fixed or perhaps something in regards to your browser was cached, because when I visit the link provided, and click into any of the news and events links, they’re showing me anticipated content. No 404s

    Thread Starter askitbasket

    (@askitbasket)

    Hi,

    Thanks for the reply

    No it isn’t fixed. You’ll see that if you click any of the individual news items, the url reverts to …/news_and_events/page (with underscores) rather than …/news-and-events/page.

    It is preferable to leave it like this rather than dealing with 404s until it can be fixed.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Gotcha, you undid some things to make the permalinks still work, instead of lead to 404s. Typically I tend to rely on the rewrite slug field instead of the archive slug, for these types of things. I also know in 1.8.0 I undid the forcing of underscores in slugs.

    By chance do you have any pages that maybe have this news-and-events slug as well? That could lead to 404 conflicts as well.

    Thread Starter askitbasket

    (@askitbasket)

    I thought that might be the answer, there was a page, albeit a draft, with that slug. I deleted the page and then moved ‘new-and-events’ to Custom Rewrite Slug field ) leaving archive slug field blank. I even went to the permalinks settings and clicked save to flush rewrite rules. Same problem as before: archive page fine, single items = 404.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not sure what to suggest otherwise at the moment as I don’t have access to debug and troubleshoot further.

    Thread Starter askitbasket

    (@askitbasket)

    Can I send the debug info to you?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    [email protected] will reach me readily enough.

    Thread Starter askitbasket

    (@askitbasket)

    Thanks very much. Sent.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Thanks for the patience here.

    Not managing to recreate a 404 with archive/single post urls at the moment.

    Just on a whim, I wonder if setting both the archive string and the rewrite slug to the same desired value may somehow help. Not seeing much else in that debug information that I can use. Most debugging would be in the interest of seeing what requests are being made for these.

    Thread Starter askitbasket

    (@askitbasket)

    Thanks. I tried that and it didn’t work. I set up a staging site and it was the same problem there. I could get it working by changing the post type slug and migrating.

    Not sure what to do next.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sadly I’ve run out of suggestions as well.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘404 error with custom rewrite to replace underscores’ is closed to new replies.