WordPress 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:
UPDATE wp_posts SET post_type = REPLACE(post_type, 'old-post-type-name', 'new-post-type-name');
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:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'my-post-type',
'paged' => $paged
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.