Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Do you have refreshed the permalinks after to include your custom post type? –  bueltge Sep 30 '12 at 13:20
    
@bueltge I created new posts but it happens all the time so I don't think a refresh would help? –  Bram Vanroy Sep 30 '12 at 13:25
    
@BramVanroy yes, refresh should help. WordPress needs to generate new rewrite rules for your custom post type. –  Mamaduka Sep 30 '12 at 13:34
add comment

1 Answer

up vote 2 down vote accepted

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 )

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.