WordPress.org

Ready to get started?Download WordPress

Forums

permalink to custom post type gives me 404 error (14 posts)

  1. kkarpieszuk
    Member
    Posted 4 years ago #

    hello

    when i have turned off custom permalinks (when wordpress links i.e. ?post=44) everything works ok. all links points to correct posts, pages, and custom post types.

    but when i turn on permalinks, links to my custom post types shows error 404. i think i read everything about this in internet and i didnt found solution.

    this is the way how i registered my custom post type (called "Domeny"):

    add_action('init', 'dodajDomeny');
    function dodajDomeny() {
    
    $labels = array(
    	'name' => _x('Domeny', 'nazwa typu postów do wystawiania domen'),
    	'singular_name' => _x('Domena'),
    	'add_new' => _x('Dodaj domenę'),
    	'add_new_item' => _x('Dodaj nową domenę'),
    	'edit_item' => _x('Edytuj domenę')
    );
    
    $args = array(
    	'labels' => $labels,
    	'public' => true,
    	'supports' => array('title', 'editor', 'page-attributes', 'custom-fields'),
    	'query_var' => true,
    	'capability_type' => 'post',
    	'_builtin' => false,
    	'rewrite' => array("slug" => "domena"),
    	'publicly_queryable' => TRUE,
    	'taxonomies' => array('cena', 'formaSprzedazy')
    );
    
    register_post_type('Domeny', $args);
    
    }

    any idea what is wrong? now in url i have, for example:

    http://example.com/domena/premium-pl/

    but page is showing error 404

  2. kkarpieszuk
    Member
    Posted 4 years ago #

    also now i see that when permalinks are turned of wordpress doesnt want to use template file for my registered custom post type.

    i added file called single-Domeny.php to theme folder, this file has quite diffrent styling than index.php. and thats why i see that wordpress uses index.php

  3. left_coaster
    Member
    Posted 4 years ago #

    Just try turning permalinks back on. Each time you add a custom post type the .htaccess file needs to be rewritten or something. Just visiting the permalinks page seems to fix the 404 for new custom post types. Meaning if you had just looked at the permalinks page without disabling them, your custom post type would have just started working.

    There are a couple notes about this hidden away in some of the many blog posts about custom post types. I had the same troubles and then spent a few hours searching for the answer too. Hope this saves you some time ;)

  4. ablears
    Member
    Posted 4 years ago #

    I had the same issue - custom post type causing a 404. Going to the permalinks page didn't solve the problem for me.

    What I realised what that my custom post type was called the same as a registered taxonomy (both called 'gallery'). As soon as I changed the taxonomy item to something else my custom post type started working.

  5. zyrq
    Member
    Posted 4 years ago #

    I found out the same thing as ablears: duplicate slugs.
    Default permalinks ?post=44 still worked.

  6. mattifesto
    Member
    Posted 3 years ago #

    It seems like there are lots of different problems and potential solutions here, but after trying every other suggested solution, none of which worked, I found something that worked. Add:

    flush_rewrite_rules();

    after you call register_post_type.

    http://wordpress.org/support/topic/permalinks-404-with-custom-post-type?replies=25#post-1893532

  7. jamiebrwr
    Member
    Posted 3 years ago #

    I had the same problem. I also had duplicate slugs. As pointed out by ablears and zyrq.

    Thanks for the help guy's!

  8. Paul
    Member
    Posted 3 years ago #

    @mattifesto

    you are a lifesaver! this is exactly why I use WP... because of the community support.

    You just saved me a whole lot of time trying to figure out why I was getting 404s everywhere

    THANKS!

  9. Devin Walker
    Member
    Posted 3 years ago #

    Adding flush_rewrite_rules(); is NOT a viable solution. I doubt it's good practice and if you're using WP-PageNavi or another pagination solution it will not work with this added to the end of your custom post type register function.

    This is a problem and is causing me and many others headaches. Has anyone had any luck? I'll keep posting back with any updates I come across. Hopefully a solution will reveal itself.

  10. zaus
    Member
    Posted 3 years ago #

    I had a problem where my custom post type wasn't showing up, and it was caused by another module doing just that -- calling flush_rewrite_rules() after it registered it's own type.

    You can check to see if your url slug is registered properly in the DB from the wp_options table: look for option_name 'rewrite_rules' (i.e. where [wp_options].[option_name] = 'rewrite_rules').

    The particular culprit in my case was facebook tabs manager.

  11. hannahsjohnson
    Member
    Posted 3 years ago #

    @left_coaster Thank you, your advice worked for me!

    I had set up my custom post types before switching over to custom permalinks. After I made that change, I got a 404 on my custom post types.

    The issue was resolved after I visited the Permalinks settings page and hit "save changes" without actually making any changes.

  12. Stefan Weise
    Member
    Posted 3 years ago #

    I've tried everything, literally everything that's been recommended in the hundreds of forum posts and blog posts all about this issue. Not to mention having now wasted several hours on this issue.

    Result: My custom post types and taxonomies consistently 404.

    One thing i should note is that my custom post types and taxonomies were working flawlessly with WP 3.1.3 and stopped working entirely (yes i'm frustrated, can you tell?) after upgrading to 3.1.4

    To sum up:
    - visiting permalink settings page: doesn't work
    - adding flush_rewrite_rules(); to functions.php: doesn't work
    - using a variety of plugins that promise to fix the issue: no worky
    - turned of all plugins to test for conflicts: no difference

    The person that finds a solution to this problem for everyone deserves a year's worth of beer, or cookies IMHO

    Someone please find a fix for this!!

  13. esmi
    Forum Moderator
    Posted 3 years ago #

    Have you tried using different names for your custom posts types & taxonomies. I've seen people run into trouble because they used a "reserved" name which threw the permalink query out of whack.

  14. Stefan Weise
    Member
    Posted 3 years ago #

    Yes i have in fact and it has not made a difference

Topic Closed

This topic has been closed to new replies.

About this Topic