Okay, here’s the deal. I am working with a child theme and I want a custom post type.
What I did
Added the following code the functions.php
of the parent theme.
add_action( 'init', 'create_fb_foto_post_type' );
function create_fb_foto_post_type() {
register_post_type('fotos',
array(
'labels' => array(
'name' => __( 'Foto's' ),
'singular_name' => __( 'Foto' )
),
'public' => true,
'has_archive' => true,
'taxonomies' => array('post_tag')
)
);
}
Created a template file single-fotos.php
which contains this code:
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
And uploaded it to the child theme’s directory.
What goes wrong
I can choose to create a new ‘Foto’ page when I’m in WordPress and it contains the tag field. But! When I want to view an example, WordPress does nothing. When I choose to submit and publish the page it works but when I then want to view it, I get a 404.
What I tried
I tried uploading the template to the parent theme’s directory (after I had created the page) but this doesn’t work either.
Any ideas?
You need to flush and regenerate your permalinks everytime you modify/add/remove custom post types or taxonomies.
Going to the permalinks page and saving should be enough
( Also your custom post type code should be in a plugin, not the theme, else the user is stuck using that theme forever )