5 Best Solutions for WordPress Custom Post Type 404 Errors

Fix custom post type 404 errors

Saif Hassan March 7, 2022

14 Min Read
0
Category: Tutorials

Are you struggling with the custom post type error in your WordPress site? Sometimes a slight tweak could make your website inaccessible. But you know- WordPress is the most powerful CMS out there. You can easily find the solution to any problem in the WordPress community.

It can be frustrating to see the message ‘Error! 404 not found, while trying to access your custom post. In this short article, we are going to show you how to fix custom post type 404 errors in your WordPress site. Keep reading.

Post Type in WordPress

Post Type is a particular term used to refer to different types of content in the WordPress sites. WordPress was primarily launched by Matt Mullenweg as a blogging platform In 2003. When WordPress started to add a different type of contents & pages, they named it as a post type.

WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp-posts database table.

WordPress added the ability for developers to register their own custom post type in the later version- 3.0. So, post type is a content type in all useful sense.

Default Post Types in WordPress

Several post types are readily available to users. And these are internally used by the WordPress default installation.

  • Post
  • Page
  • Attachment
  • Revision
  • Navigation Menu
  • Custom CSS
  • Changesets
  • User Data Request

…and an opportunity to add any post option according to your need. That’s called a custom post type!

Why Need a Custom Post type in WordPress?

Custom post type is a content type like other regular posts and pages. You can create your custom post types and name them whatever you want. Since WordPress evolved itself from a simple blogging platform into a robust CMS, you can use it for any type of purposes. When you need to use this platform in your specialized field, you may need to create a special post type.

custom post- fix 404 error

When you don’t find your contents fit the default post or page type, you should create a custom type as your own. The reasons can be many!

  • To make your contents more relevant and fit
  • To differentiate your presentation
  • To ensure more attractiveness
  • To efficiently organize your all type of contents
  • To avoid a common boring type posts

…And many more

Some typical example of custom post types are-

  1. Products
  2. Courses
  3. Portfolio
  4. Tutorials
  5. Reviews
  6. Recipes etc.
KadenceWP

How to Fix 404 Errors in Custom Post Type

Bugs and errors are common facts in the software industry. Anything could happen anytime. But luckily, there is always a simple solution in the WordPress community to fixing the problem. If you are trying to fix custom post type 404 error, read on.

We have listed some common and easy ways to fix custom post type 404 errors in your WordPress site.

A permalink is a permanent URL to your posts, categories, archive, and other similar pages. It’s the unique link that directs to a specific, corresponding post.

Permalink setting is one of the most common reasons you could get 404 errors on your custom post type. There are many fixing options available for you. This is the most useful and easiest way to solve custom post type 404 errors.

  • Set your custom permalink structure from your dashboard (such as %postname%)
  • Go to Settings > Permalinks, in your admin dashboard
  • Make a note of the current setting since you need to temporarily change it.
  • Select the Plain radio and click on Save Changes at the bottom of the page.
permalink- fix 404 error
  • See whether your single custom post pages return 404 error pages or not
  • If return, go back and change permalinks back to default and save
  • Now try setting the custom permalink again and save!

This may not work if your permissions aren’t set correctly. In that case, you may need to update your .htaccess file manually.

Set up .htaccess File Manually to Fix Custom Post Type 404 Errors

  • Just log into your site via FTP or SFTP
  • Browse to your root WordPress directory- the same place where your wp-config.php file and a wp-content folder is located.
  • You should find here a file named .htaccess which you can transform.

Note: if you don’t see this file, make sure your FTP program has the option to display hidden files enabled. If there isn’t one then simply create one.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Remember: Make sure to back up the file on your computer first, when you are changing an existing .htaccess file. There is a possibility to mess something up!

2. Check the Title or Slug Conflict

Another thing that may cause a 404 error is the title/slug similarity. The page you have to display your post type post, it has the same title/slug as your actual post type. For example, if you have a post type named ‘portfolio’ and you also have a main ‘Portfolio’ page, both with the title/slug ‘portfolio’ this creates a conflict. This conflict could cause 404 errors on your singular post type posts. That’s why you often find that the portfolio post type uses the slug ‘projects’ or ‘portfolio-item’ or something else for the singular slug.

slug- fix 404 error

Fix 404 errors by changing the title/slug:

  1. You can change the page name. It will be different than the custom post type
  2. Also, you can change your custom post type slug which is done by altering the rewrite parameter while registering your custom post type.
weGlot

3. Fix 404 Errors by Switching to a Default WordPress Theme

This is the 3rd step or option where your real troubleshooting begins. If you have a custom theme installed in your site, switch to one of the default WordPress themes like the Twenty Fifteen, Twenty Sixteen or Twenty Seventeen.

Everyone knows that debugging is twice as hard as writing a program in the first place. So if you are as clever as you can be when you write it, how will you ever debug it? -Brian Kernighan

Now, re-save the permalinks structure again and test. Hope you will find your page all ok.

4. Fix 404 Errors through Plugin Updates

If you see the problem still after trying all the above options, you need to try this trick. Follow the instructions.

  1. Disable all your installed plugins and resave the permalinks again. This will definitely fix your problem so test and see. You could check out the post on how to add a plugin to your WordPress site. Now that we know-
  • Your theme is fine
  • Your custom post type is fine
  • And your permalinks also have been flushed.

There is only one possibility. It’s one of your plugins that is asking the flush function and doing wrong.

https://wphive.com/reviews/plugins/best-wordpress-plugins/amp/
  1. This is the time to re-enable all of your plugins.
  • Start activating all your plugins one at a time
  • Resave the permalinks separately after each activation
  • Test your custom post type

This will pinpoint your actual problem source. If there is any problem, report it to the developer or simply could try to fix it by yourself!

5. Further Troubleshooting for Advanced Users

Another possible cause of 404 errors is avoiding flushing rewriter rules. Whenever a new post type is registered you need to ‘flush’ your rewrite rules in WordPress. Follow the instruction to fix 404 errors by flushing the rules every time.

  • Go to Settings > Permalinks from your admin dashboard.
  • Click on Save Changes at the bottom of the page.

Security is one of the top significant facts that you need to consider from the first day of your web-journey. Fix 404 errors to make your site more secure and flexible.

  • As a developer, you may consider automatically flushing the rewrite rules for your end user. You could do that when you are working on a custom theme/plugin with registered post types.

Look at below sample codes you may use to automatically flushing the rewriter riles.

// Code for themes 
add_action( 'after_switch_theme', 'flush_rewrite_rules' ); // 

Code for plugins register_deactivation_hook( __FILE__, 'flush_rewrite_rules' ); register_activation_hook( __FILE__, 'myplugin_flush_rewrites' ); function myplugin_flush_rewrites() { //

 call your CPT registration function here (it should also be hooked into 'init') myplugin_custom_post_types_registration(); flush_rewrite_rules();
 }

When you see a 404 error, use and apply the above options. Use the trick to fix 404 errors in your WordPress site.

Create a Custom Post Type Easily with a Free Plugin

Use a plugin to create any custom post type you need within a few seconds! There are lots of useful plugins in the WordPress industry.

Our pick for you is the WordPress User Frontend.

Why WordPress User Frontend is the Best to create a custom post?

  • It’s easy and secure
  • First in the industry and one of the most used plugins
  • Multiple options and categories, and its free!

Check how to create a custom post type using WPUF within a few seconds!

Closing Thoughts on Custom Post Type 404 Error

Errors could happen anytime. You need to fix 404 errors on your website quickly. If you couldn’t fix your 404 error, do leave a comment and we will try to come up with a solution.

If you don’t have a blog site yet, check out how to create a WordPress blog in minutes or build an e-commerce site today with WordPress!

Follow us on Facebook and Twitter for more beginner-friendly WordPress tutorials and reviews.

A2 Hosting
Wordpress Icon

Disclosure: WP Hive earns a commission when you buy through partner links. It does not influence the unbiased opinions of our writers. Learn more →

Share:

https://wphive.com/tutorials/how-to-fix-custom-post-type-404-errors-in-wordpress/Copy icon

Saif Hassan

Product Manager by passion & profession. Lead Product Manager at weDevs, former PM @ Poptin. Passionate about writing & tech. He's an advocate of Human-Centered Design and believes that websites and the tools used to build them should be well crafted, intuitive, and accessible. Cyclist. Reader. A WordPress ninja 🥷, HCI expert & a design thinker 💡

Subscribe To Our Newsletter

Newsletter Subscription Form

Leave a Reply

Your email address will not be published. Required fields are marked *