WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type UI
[resolved] Permalinks causing 404 errors on custom post type (25 posts)

  1. pixelkicks
    Member
    Posted 11 months ago #

    Hi,

    I have created the following custom post type:

    events

    Permalinks are set to:

    /%postname%/

    A sample URL for one of the created events is:

    http://www.domain.com/events/business-after-5-with-qantas-in-the-frame/

    Yet this gives a 404 when we try it. What do we have to do to get the permalinks working? We've already tried re-saving the permalinks a few times.

    Chris.

    http://wordpress.org/plugins/custom-post-type-ui/

  2. pixelkicks
    Member
    Posted 11 months ago #

    Further to this, the links don't even work with standard permalinks.

    Is there something I'm missing? I've set any taxonomies but I assumed I didn't need to?

    Chris.

  3. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    So the links to your CPT posts aren't working even without permalinks?

    Nope, taxonomies aren't a requirement for it to work.

    Could you pastebin the settings you used for your CPT? I'll see if it gives me the same issues at all. You'll be able to get them in a pasteable format via the "Get Code" link when you go to edit the CPT. Ignore the "broken" quotes aspect, that's fixed in the next, pending, release, and this isn't what does the actual registering.

  4. pixelkicks
    Member
    Posted 11 months ago #

    Hi Michael,

    Thats right. I've spent the last two hours struggling to get any links to work at all. Normal posts and pages work fine with any permalink structure in place though.

    This is a dev site we're working on and its hosted on a Windows server. This wouldn't make a different for the rewrite rules would it?

    Custom Post Type settings:
    http://pastebin.com/dr9UGrwN
    (incidentally they give an error if I try and paste into functions.php manually)

    Web.config:

    <rule name="wordpress" patternSyntax="Wildcard">
    	<match url="*"/>
    		<conditions>
    			<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
    			<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
    		</conditions>
    	<action type="Rewrite" url="index.php"/>
    </rule>
  5. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    Actually, I think it would have an influence on rewrites. Linux hosting and Windows hosting aren't the same with this topic. That said, I'm also out of the running for good help, as I have never debugged IIS issues with rewrites :(. I'm wondering if that's the primary area of issue.

    Yeah, you'd need to review the pastebin code before pasting into functions.php and hitting save, make sure it's done right. Like I said in my first reply, it's pending fixed in the next release. Hopefully soon.

  6. pixelkicks
    Member
    Posted 11 months ago #

    Hmm that makes things awkward!

    Should the permalinks work "straight out of the box" generally then? Do you have an example of a .htaccess file for my sceneario above I could use to compare? Might help with any debugging.

  7. pixelkicks
    Member
    Posted 11 months ago #

    Ok, this is getting strange now. I've just tried the following code directly in my functions.php, and it works perfectly now!

    http://pastebin.com/2ipGnAx6

    The codes is what I took using "Get Code", but I had to amend a few extra unneeded apostrophes. I resaved the permalinks setting and it worked. The web.config file remains unchanged though.

    Why would putting the code directly in functions.php cause it to work? Surely its exactly the same?

    Any ideas?

    Chris.

  8. pixelkicks
    Member
    Posted 11 months ago #

    Just for extra details, I commented out the code, resaved the permalinks settings and straight away the link gives a 404.

  9. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    One would think so. Here's an example from a linux hosted version, with one of the default options available.

    # BEGIN WordPress
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
  10. ibecker
    Member
    Posted 11 months ago #

    I was having the same problem and it was driving me crazy for 2 weeks. I was able to fix it by going to the Advanced Options on the post type I was trying to view, and change "Has Archive" to "True" and boom, they worked!

  11. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    thanks for the feedback ibecker. Hopefully that helps pixelkicks. Now to have me remember that that needs to true for archives to work. :D

  12. ucarman2002
    Member
    Posted 11 months ago #

    hello
    i am having the same problem. sorry no such page error when previewing changes to published post.
    i have been reading forums for a week and have tried all the recommended fixes except adding flush rewrite rules. not sure where to place this code.
    any help with this?

  13. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    ucarman2002, just visiting the permalinks settings page should flush you rewrite rules.

  14. pixelkicks
    Member
    Posted 11 months ago #

    That sounds positive ibecker, and I'll give it a try in future.

    As it was I had to stop using the plug-in, instead using some code I found on another website to create the custom post types. Got it working perfectly in the end.

    Maybe it might have just been the "Has Archive" settting all along.

  15. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    No worries here. I'd rather you get what you need done than if it involves our plugin :)

  16. ucarman2002
    Member
    Posted 11 months ago #

    hello
    visiting the permalinks page does not solve problem.
    preview changes after post is published still produces 404 error. page not found.
    have tried in different themes.
    have tried disabling all plugins,except custom post type UI.
    I believe the problem was caused by having posts with the same name as the custom post type. I deleted all of those and tried all of the above again. no luck.
    any ideas?
    thanks

  17. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    ucarman2002, just as a quick check, did you make sure your registered CPT is set to have archives? It's one of the "advanced options" that are available by clicking the link below the initial 4 inputs.

  18. ucarman2002
    Member
    Posted 11 months ago #

    hello
    all registered CPT set to have archives true

  19. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    not sure at this point, ucarman2002, sorry. Maybe someone else has an idea.

  20. António Pinto
    Member
    Posted 2 months ago #

    Your Custom Post Type has to have Archive set to true to enable Permalinks.

    To update the Permalinks structure you can add the following function to your functions.php file:

    // ==============================================
    // Flush Permalinks on Save Post
    // ==============================================
    
    //Create a Function to Flush Permalinks
    function nr_flush_permalinks() {
    	/* Call WordPress rewrite function to flush rules.
    		http://codex.wordpress.org/Rewrite_API/flush_rules */
        $wp_rewrite->flush_rules();
    	// Do anything you wish to do more....
    }
    //Add Function "n_flush_permalinks()" to the "save_post" action hook:
    add_action( 'save_post', 'nr_flush_permalinks()' );
  21. Michael Beckwith
    Member
    Plugin Author

    Posted 2 months ago #

    for anyone stopping my and seeing this thread, while Antonio does have the right idea that you need to flush your rewrite rules when you register new posts types or taxonomies, I'm not sure having them flushed every time a post gets saved, which can be quite frequently. This would cause a lot of overhead. Also just visiting the permalinks settings page is supposed to flush them as well, and nowhere near as frequently as the save_post hook.

  22. arjanvandenbos
    Member
    Posted 2 months ago #

    I have a similar issue, took me a while to nail it down to Custom Post Types UI but that definitely seems to be the cause.
    Scenario: site under development with 3 Custom Post Types + 4 Custom Taxonomies.
    Everything was working fine, with /%postname%/ permalink but somehow something happened, most likely after adding the 3rd post type.
    Now the /%postname%/ permalink does not work, it results in most pages (normal pages, not posts - but strangely enough not all of them) going to the posts 'Home' page (not 404).
    The 'default' permalink is working fine, so does the Numeric '/archives/%post_id%' permalink that I am using now.

    I have tried different ways to correct this:
    - not a theme issue: also happens with default WP theme
    - not connected to another plugin as it also happens with all plugins (except CPT UI) disabled
    - even moved a copy of the site to another server: still same issue
    - archiving for CPT is on
    - changed page names with possibly permalinks conflicting with CPT
    - checked .htaccess file

    I see that you are looking for beta testers for 0.9 version; could that version possibly address this issue ?

  23. Michael Beckwith
    Member
    Plugin Author

    Posted 2 months ago #

    At the time of the posting, I definitely was looking to be looking for beta testers, but sadly I fell off the wagon completely with 0.9 since then, due to other work in-company, and I haven't touched the plugin since January. So as it stands, i'm still going to be looking to look for beta testers, but it's still not at a point of being in beta :| So much refactoring 8-|

  24. arjanvandenbos
    Member
    Posted 2 months ago #

    I found the cause of my permalink problems.
    Not so much the plugin itself but the fact that I used 'year' as a slug for one of the CPT's. I now know that this slug should not be used and is reserved for WordPress (http://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms).

    You might want to build in some sort of alert for the users of the plugin in a next version to avoid them making the same mistake.

  25. Michael Beckwith
    Member
    Plugin Author

    Posted 2 months ago #

    Good to hear that you got that resolved. I've made a github issue for myself to remind me to do something about that list of reserved terms, if I haven't done something already with my beta copy.

Reply

You must log in to post.

About this Plugin

About this Topic