I just installed a new wp installation. I have created a new child theme based on the TwentyTwelve theme. In the child theme functions.php, I have created a new custom post called “news”. I have added two posts in the “news” and when I view either of them, I get a “page not found” error. See screenshot: http://pasteboard.co/dtIOK6g.jpg
I am expecting the posts to be displayed but am getting a 404 page. why.
Update (to make my question clear):
From installation, I have done very little work, apart from the following:
- Added a new child theme (of Twenty Twelve)
- I have applied the new child theme
- I have created a new custom post by updating the creating a functions.php in the child theme and ading in this code here (http://pastebin.com/DKny8QH1)
- In WP admin, I have created a 2 new posts under news (new custom post created above)
- if I try to access the post, i get 404 (as shown in screenshot above). However, I can access the posts created normally.
Thanks
RESOLVED: This is really weird but I have resolved it. It appears I needed to reselect the “Post name” option for my permalinks settings even though it was already selected. Selecting this option again solved my problem. Sorry about any confusion.
- I went to settings > permalink
Actually, this is a common problem.
When you add a custom post type, you’re also registering a new rewrite rule with WordPress. However you must flush your rewrite rules after registering things in order to get WordPress to recognize them.
With a plugin, this is fixed by hooking your CPT registration to both
init
(so it’s usable) and the plugin’s activation hook. Then, inside the plugin activation hook, you manually callflush_rewrite_rules()
to reset things.Since there is no analogous theme activation/deactivation setup, you can use options to set when the theme has been loaded. For example:
In a nutshell. This code will:
init
as usual.flush_rewrite_rules()
multiple times.RESOLVED: This is really weird but I have resolved it. It appears I needed to reselect the “Post name” option for my permalinks settings even though it was already selected. Selecting this option again solved my problem. Sorry about any confusion.
I went to settings > permalink