Solve those Peski 404 errors you're getting with WordPress Custom Post TypesWordPress 3.0′s Custom Post Types are undoubtedly a valuable feature. They allow you to extend the platform like never before, but also can occasionally cause some problems when developing; most commonly 404 issues.

The main issues I come across are problems with permalinks, pagination and single postings. Here’s the rundown I go through to fix these issues:

1. Single Custom Post Type 404 Error

Scenario: You’re querying the custom post types properly but when you click on a link to an individual post it goes to a 404 error page rather than single posting.

You CANNOT have a Custom Post Type and Page with the Same Name

Solution: Rename the Custom Post Type or Page with the same name so they are different. If you elect to change the custom post type name you will need to do a MySQL query to find-and-replace all post types with the old name to the new one. Don’t worry, this isn’t that hard. Here’s a MySQL query that will effectively change the post_type name of the old name to the new one:

Also, keep in mind that if you change the Custom Post Type name you may have to do some 301 redirects as this will change the slugs and Google may get a little cranky.


2. WP-PageNavi with Custom Post Types Shows 404 Error

Scenario: You’re using WP-PageNavi for pagination and for when you click on the page items it returns a 404 error page rather than the actual post. You also have your permalink structure set to other than default ( /%category%/%postname%/ etc.)

Are You Querying Posts Properly?

Solution: Change your query code to check to see if there is a paged query variable and if not setting it to 1:

Then refresh your permalinks by visting the permalinks option panel under the settings section in your WordPress backend.


3. Pagination Fix for Categories and Custom Post Types

Scenario: You have registered both a custom post type and custom taxonomies and pagination returns a 404 page for the categories.

Install the Category Pagination Fix Plugin

There’s a great plugin that will fix the custom taxonomy pagination issue without you even to have to touch code: wordpress category pagination fix


Have a Solution or Different Issue? Help us out.

There’s no denying the power behind custom post types. They just like to act a bit funky sometimes. A lot of the issue arise from permalink structures and a lot of behind-the-scenes code.

Please, don’t hesitate to comment below with your problems, solutions, changes or recommendations. We hope you found some value from this post.

Devin Walker is a San Diego-based WordPress Developer and enthusiast. He is the author of several popular and highly-rated WordPress themes and plugins. In his free time he enjoys playing Golf and traveling.

Follow
Devin

Is your WordPress Running Slow?

Milliseconds are money. Website speed is extremely important. We highly recommend WP Engine. Why? Because they make a sluggish WP site fast, support is great and they have excellent uptime.

WP Engine Logo
  • Dwiser

    THANK YOU THANK YOU THANK YOU!!!!!!!!!!! I’ve been searching for hours for a solution!!!!

    • http://twitter.com/innerwebs Devin Walker

      Glad to be of service!

  • Dwiser

    THANK YOU THANK YOU THANK YOU!!!!!!!!!!! I’ve been searching for hours for a solution!!!!

    • http://twitter.com/innerwebs Devin Walker

      Glad to be of service!

  • Leslie

    THANK YOU!!!! I got here from help over at wordpress.org and wanted to take a minute to say thanks for cataloging this issue so others can find it.

    I was pulling my hair out repeatedly and can’t believe it turned out to be something as simple as “don’t name custom posts and pages the same thing”. Argh – slaps forehead! Now, of course, it seems like such a no-brainer ;). Did I miss where this tip was included in the Codex? LOL

    THANKS SO MUCH!

  • Leslie

    THANK YOU!!!! I got here from help over at wordpress.org and wanted to take a minute to say thanks for cataloging this issue so others can find it.

    I was pulling my hair out repeatedly and can’t believe it turned out to be something as simple as “don’t name custom posts and pages the same thing”. Argh – slaps forehead! Now, of course, it seems like such a no-brainer ;). Did I miss where this tip was included in the Codex? LOL

    THANKS SO MUCH!

  • Ss888

    Many thanks – Have read so many posts regarding custom post types and error 404′s, yet this is the first one that has mentioned the fact that you can’t have a page and custom post type of the same name! Awesome! Problem fixed!

  • Ss888

    Many thanks – Have read so many posts regarding custom post types and error 404′s, yet this is the first one that has mentioned the fact that you can’t have a page and custom post type of the same name! Awesome! Problem fixed!

  • Phil

    Hey noob question – can you give me an example of where I would put that mySQL query and how it should be written in PHP to make it work? Thanks :)

    • http://cameronpreston.com Cameron

      I’d just throw that SQL command in a PHPMyAdmin SQL input form

  • Phil

    Hey noob question – can you give me an example of where I would put that mySQL query and how it should be written in PHP to make it work? Thanks :)

    • http://cameronpreston.com C- Pres

      I’d just throw that SQL command in a PHPMyAdmin SQL input form

  • http://twitter.com/jhinson Joseph Hinson

    I stumbled on this a bit too late. I also ran into an error where EVERY page 404s, turns out it was a rewrite issue with one of my taxonomies. Only happened when I edited a page though. Fortunately I didn’t need the rewrite so I changed it to ‘false’ and it fixed the problem.

    Love your site by the way.

  • http://twitter.com/jhinson Joseph Hinson

    I stumbled on this a bit too late. I also ran into an error where EVERY page 404s, turns out it was a rewrite issue with one of my taxonomies. Only happened when I edited a page though. Fortunately I didn’t need the rewrite so I changed it to ‘false’ and it fixed the problem.

    Love your site by the way.

  • Adam

    For #1 (Single Custom Post Type 404 Error), where do you place this piece of code? I inserted it into my functions.php file, but got a “syntax error”.

  • Adam

    For #1 (Single Custom Post Type 404 Error), where do you place this piece of code? I inserted it into my functions.php file, but got a “syntax error”.

  • Seb_paris

    Hey,

    I tried all your tips and my issue is still unsolved.

    1. I have renamed my category (“liste_poteries”) so the custom post type name (“Poterie”) is different from the category name.

    2. I use wp-paginate plugin, i think it works the same way as wp-pagnavi.
    I have already set the paged variable as described above

    3. I installed the pagination fix plugin and activated it in wordpress

    On the first page of my category, the first posts are displayed. When I choose the second page, etc…, 404 error.

    Can you help me please ?

    Sorry for the french wordings.

  • Seb_paris

    Hey,

    I tried all your tips and my issue is still unsolved.

    1. I have renamed my category (“liste_poteries”) so the custom post type name (“Poterie”) is different from the category name.

    2. I use wp-paginate plugin, i think it works the same way as wp-pagnavi.
    I have already set the paged variable as described above

    3. I installed the pagination fix plugin and activated it in wordpress

    On the first page of my category, the first posts are displayed. When I choose the second page, etc…, 404 error.

    Can you help me please ?

    Sorry for the french wordings.

  • A9500324

    Devin Walker, you are my hero of the day! Nah, week!!

    Hundreds of google queries, dozens of board posts, and now your POINT ONE was the solution of all of my problems I thought I would never be able to solve – I even started to hate WordPress! I was going mad cause of the 404 I always got just on specific subpages which were sub-related to same-named custom content. THANK YOU! THANK YOU VERY MUCH! I hope others will find this post earlier so they don’t have to suffer! :) Now November can come!

    • http://wordimpress.com Devin Walker

      Glad this helped you!

  • A9500324

    Devin Walker, you are my hero of the day! Nah, week!!

    Hundreds of google queries, dozens of board posts, and now your POINT ONE was the solution of all of my problems I thought I would never be able to solve – I even started to hate WordPress! I was going mad cause of the 404 I always got just on specific subpages which were sub-related to same-named custom content. THANK YOU! THANK YOU VERY MUCH! I hope others will find this post earlier so they don’t have to suffer! :) Now November can come!

    • http://www.wordimpressed.com Devin Walker

      Glad this helped you!

  • Zornitsa Stoyanova

    This is a great post. Thank you… but still not solving my problem.
    I have custom post type called “events”.
    I’m showing all of my events on the home page (along with other posts) and as well as a dedicated “calendar of events” page. 
    Earlier today I made a page called “Events” by mistake.. deleted it and removed it from the trash. Unfortunately, I’m still getting “post not found” when I try to view my custom posts as a single post.

    I even tried renaming the custom post events with your 1st solutions, but nothing changed.
    I updated permalins … no change.

    I’m also using “Post type archives” plug in, but I don’t think its interfering. 

    Any ideas?
    Thanks so much for the help.
     

  • Zornitsa Stoyanova

    This is a great post. Thank you… but still not solving my problem.
    I have custom post type called “events”.
    I’m showing all of my events on the home page (along with other posts) and as well as a dedicated “calendar of events” page. 
    Earlier today I made a page called “Events” by mistake.. deleted it and removed it from the trash. Unfortunately, I’m still getting “post not found” when I try to view my custom posts as a single post.

    I even tried renaming the custom post events with your 1st solutions, but nothing changed.
    I updated permalins … no change.

    I’m also using “Post type archives” plug in, but I don’t think its interfering. 

    Any ideas?
    Thanks so much for the help.
     

  • James John Malcolm

    I’m having the “category and pagination problem” in wordpress 3.3.2.
    I have (now) the Custom Post Type Category Pagination Fix plugin installed, caching plugins deactivated, and the following code to list the items:

    http://pastebin.com/hzCC8RRA
    (Which boils down to showing ‘agenda’ post types in the current category (theme-nights))

    The Agenda page has the slug agenda2, the Theme-nights page, theme-nights. There’s no special theme-nights custom post type, so that shouldn’t matter.

    • http://james.gameover.com/ James John Malcolm

       And permalinks are standard (e.g. bla.com/?cat=56&paged=2)

  • James John Malcolm

    I’m having the “category and pagination problem” in wordpress 3.3.2.
    I have (now) the Custom Post Type Category Pagination Fix plugin installed, caching plugins deactivated, and the following code to list the items:

    http://pastebin.com/hzCC8RRA
    (Which boils down to showing ‘agenda’ post types in the current category (theme-nights))

    The Agenda page has the slug agenda2, the Theme-nights page, theme-nights. There’s no special theme-nights custom post type, so that shouldn’t matter.

    • http://james.gameover.com/ James John Malcolm

       And permalinks are standard (e.g. bla.com/?cat=56&paged=2)

  • closemarketing

    The first issue saves me the life! Thanks. I had in the trash old entries and they had conflict with CPT.
     

  • closemarketing

    The first issue saves me the life! Thanks. I had in the trash old entries and they had conflict with CPT.
     

  • http://www.facebook.com/profile.php?id=100001308297161 Klara Nilsson

    I still have the issue #1.
    I have a post type called malort_released that collect from utgivet.php-template that I apply to the page Utgivet.

    Permalink is http://localhost:8888/wordpress/utgivna/aterigen/

    In functions
    ‘rewrite’ => array(‘slug’ => ‘utgivna’, ‘with_front’ => FALSE),

    I tried the input-query in phpMyAdmin and it affected 0 rows as I try making new posts everytime they fail.. if you have any input at all I would be sincerely grateful!

  • http://www.facebook.com/profile.php?id=100001308297161 Klara Nilsson

    I still have the issue #1.
    I have a post type called malort_released that collect from utgivet.php-template that I apply to the page Utgivet.

    Permalink is http://localhost:8888/wordpress/utgivna/aterigen/

    In functions
    ‘rewrite’ => array(‘slug’ => ‘utgivna’, ‘with_front’ => FALSE),

    I tried the input-query in phpMyAdmin and it affected 0 rows as I try making new posts everytime they fail.. if you have any input at all I would be sincerely grateful!

  • Stefano Calabrese

    add_action(‘template_redirect’, ‘StefanoAI_theme_filter_404′, 1);

    function StefanoAI_theme_filter_404() {
    global $wp_query;
    preg_match(“//green-location/(.*)/”, $_SERVER['REQUEST_URI'], $m);
    if (!empty($m)) {
    query_posts(array(‘post_type’ => ‘location’, ‘name’ => $m[1]));
    return;
    }
    }

  • bucur

    I have this code but when I give the page 2 does not work, error. I tried different variations not find solution for pagination to go to page 2, 404. I resave permalinks nothing…

    /**

    * Template name: Portfolio

    */

    get_header(); ?>

    ‘portfolio’, ‘showposts’ => 6, ‘paged’ => $paged ));

    ?>

    <a href="”>

    <a href="” title=”" >

    ” . __( ‘Pages:’, ‘owd’ ),

    ‘after’ => ”, ) ); ?>

  • bucur

    I have this code but when I give the page 2 does not work, error. I tried different variations not find solution for pagination to go to page 2, 404. I resave permalinks nothing…
    LINK
    http://wpteme.info/portfolio/