• Resolved Anders Norén

    (@anlino)


    I’m working with a custom post type called ‘portfolio’, and I’m trying to use custom post type templates to create an archive page and a single page for the post type. However, I’m unable to get either to work. When I visit the url for a post using the post type, I get the 404 page.

    The post type is called ‘portfolio’, and the files are called ‘single-portfolio.php’ and ‘archive-portfolio.php’. I have flushed the permalink settings (rewrite rules). I’m running XAMPP on a Mac.

    Code:

    add_action('init', 'portfolio_register');    
    
    function portfolio_register() {
        $args = array(
            'label' => __('Portfolio'),
            'singular_label' => __('Projekt'),
            'public' => true,
            'show_ui' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'has_archive' => true,
            'rewrite' => true,
            'supports' => array('title', 'editor', 'thumbnail')
           );    
    
        register_post_type( 'portfolio' , $args );
    }
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Anders Norén

    (@anlino)

    To clarify, it doesn’t even revert to single.php or index.php – it just goes to 404.php. I’m lost.

    Julien Vocat

    (@julienvocat)

    Hi !

    Try to add this :

    register_post_type( ‘portfolio’ , $args );
    flush_rewrite_rules();

    Thread Starter Anders Norén

    (@anlino)

    You are my hero. Thank you.

    @julien Vocat, you’re my hero, too! Still don’t understand tho why it didn’t work without flush_rewrite_rules();

    @julien Thanks Really helpful ??

    inserting the flush_rewrite_rules() call did not work for me. I am having trouble getting my permalinks for my CPTs to work. My site is directing my posts to the CPT name rather than the rewritten slug. I’ve tried going to the permalinks page and resaving but that didn’t work. also, my CPTs are using single.php instead of single-cpt_name.php. Any ideas for what else I can try? Thanks.

    correction, my CPTs are using the correct single.php file, so forget about that, but my slugs still aren’t working for them as I said.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Post Type Templates not working’ is closed to new replies.