WordPress posts and pages are stored in wp_posts table. You may wonder how it differentiates? The post_type column stores the value ‘post’ for post and ‘page’ for page. We can have our own custom post type also. For example if we add custom post type ‘portfolio’ then, what gets stored under post_type column is ‘portfolio’
It’s very easy to have custom post type. But my humble advise is to check twice whether it is really needed? If it is really needed then do go for it, because there is nothing like it, Trust me..!
Instead of dictating everything step by step I will recommend reading codex link for ‘Custom Post Type‘. This will certainly give you up to the mark knowledge about the same.
Solution to 404 issue
Finally I got the solution for WordPress Custom Post Type 404 issue.
After doing a lot ofย search and banging my head against a wall, I came to know that we can not have a PAGE and CUSTOM POST TYPE with the same name. I repeat, we cant have a PAGE and CUSTOM POST TYPE with the same name. Since, WordPress generates the permalink on the fly as per the name/title of the page we enter while creating, it conflicts with the Custom Post Type. For example if you have page name ‘ Portfolio ‘ please do not make mistake of defining Custom Post Type as
register_post_type('portfolio',$args);
If you do, you will get 404 headache either with your pagination or any links e.g. Read More. So simply make either of the name plural.
Hope this helps, and saves you precious time! ๐
15 Comments
Ah, yes this is a very important piece of information.
Although, I have not yet encountered 404 issues with post types, I can say this would definitely save me in the future when this type of issue occurs.
Thanks! ๐
Yes, thanks Ryan. The reason why i thought about posting this was that I faced this issue myself and when I searched for the solution, I found people who told me to fix it via .htaccess rule and what not. But the the solution was simple and worth sharing ๐
The suggestion does not solve the problem. I have two custom posts โtestingโ and โnewsโ, and only the page that comes by default, โaboutโ. When i try to access the page โnewsโ goes to page 404.
Hey Leandro, You must have created two pages with names ‘testing’ and ‘news’, you might have also created two page templates
to assign to those pages respectively. What happens is that WordPress will create the slug dynamically. So in your case,
since you are having problem with the ‘news’ page, there must be some category or post or tag with the same name and slug as ‘news’.
This confuses WordPress and it redirects to page 404. Please crosscheck the same and let me know whether this helps…! ๐
Installed the database again, only added two posts, one in news, and other in tests. I keep getting redirected to page 404. A Brazilian friend, discovered the problem, contacted the team of wordpress, but it has not received responses from BUG.
http://wordpress.org/support/topic/permalinks-404-with-custom-post-type
When you register a custom post argument “rewrite” the slug has to be different from the registered name of the custom post. Ex:
$args = array('rewrite' => array('slug' => 'tests', 'with_front' => false));
register_post_type ('test', $ args);
Simple resolution…
When I faced this problem, what I said worked for me. What you are saying seems to be one more case where it redirects to page 404. Thanks Leandro, this has definitely added one more page to my knowledge ๐
We will pass on knowledge to others, will help a lot.
Prasad Nevase,
YOU SAVED THE DAY! Thanks for posting the fact that you CANNOT HAVE A PAGE NAMED THE SAME AS A CUSTOM POST TYPE. This will always return a 404 page when trying to view the single posting. You solved my issue and I thank you and like you on Facebook.
Hi Devin,
Nice to know that my article saved your time. I visited your blog, its full of knowledge and has a very good design. Keep it up…!
What if you want to keep the same permalinks names? http://wordpress.org/support/topic/pages-and-custom-types-cannot-have-the-same-name-so-how-to-structure-permalinks
Hey Gianfranco, thanks for sharing that. Really, I also wonder that how come nobody in whole WordPress community has not faced such a problem!
I don’t know about anyone else but this freakin 404 error is giving me the sh!ts and i wanna through my computer out of the window (even though i know its wordpress and not actually my computer)….Anyway, my post name is NOT the same and i’ve gone through the whole .htaccess route, but still nothing. Unfortunately the site http://www.maxitaxishuttles.com is my first WP site so i’m a bit of a newbie in the world of WP. So if someone could send a simple suggestion on how to fix this 404 error it would be much appreciated. Afterall that the hell is a blog that you cannot place a post on???? Seriously!
Hey Stevie,
Can you provide me a URL where you are listing your custom post type posts and pagination?
Thanks
Hi Prasad,
Thanks for replying….as it turns out, i changed the permalinks setting from custom to one of the others and it now works! The url is http://www.maxitaxishuttles.com/2011/06/sydney-shuttle-bus-business-sale/
As you can see, i change the permalinks to the year and month setting….however i would have preferred that it simply had the post name without the dates.
As previously mentioned in my last post, i am a newbie with WordPress and it all seems very different to how i usually build a site….I guess it’s the learning curve one must go through! Thanks ๐
I hve deleted all the posts and pages from my wordpress still getting 404 error.When I add new page it says successfully added but when
I press preview or view page option I get 404 error page. Can’t understand wht shall I do.