2

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?

3
  • Do you have refreshed the permalinks after to include your custom post type?
    – bueltge
    Commented Sep 30, 2012 at 13:20
  • @bueltge I created new posts but it happens all the time so I don't think a refresh would help? Commented Sep 30, 2012 at 13:25
  • @BramVanroy yes, refresh should help. WordPress needs to generate new rewrite rules for your custom post type.
    – Mamaduka
    Commented Sep 30, 2012 at 13:34

1 Answer 1

4

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 )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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