WordPress : More than one custom post = 404

I have created two custom post types, where the first works just fine, but the second end up as a 404 – Page not found. I am not sure why this is, and it doesn’t seem logic to me…

Here is the code:

Read More
/** First custom post (prosjekt = projects) **/
add_action( 'init', 'register_cpt_prosjekt' );

function register_cpt_prosjekt() {

$labels = array( 
    'name' => _x( 'Prosjekter', 'prosjekt' ),
    'singular_name' => _x( 'Prosjekt', 'prosjekt' ),
    'add_new' => _x( 'Legg til ny', 'prosjekt' ),
    'add_new_item' => _x( 'Legg til nytt prosjekt', 'prosjekt' ),
    'edit_item' => _x( 'Rediger prosjekt', 'prosjekt' ),
    'new_item' => _x( 'Nytt prosjekt', 'prosjekt' ),
    'view_item' => _x( 'Vis prosjekt', 'prosjekt' ),
    'search_items' => _x( 'Søk i prosjekter', 'prosjekt' ),
    'not_found' => _x( 'Ingen prosjekter funnet', 'prosjekt' ),
    'not_found_in_trash' => _x( 'Ingen prosjekter funnet i søppelet', 'prosjekt' ),
    'parent_item_colon' => _x( 'Parent Prosjekt:', 'prosjekt' ),
    'menu_name' => _x( 'Prosjekter', 'prosjekt' ),
);

$args = array( 
    'labels' => $labels,
    'hierarchical' => false,
    'description' => 'Prosjekter',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', 'revisions' ),
    'taxonomies' => array( 'post_tag' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 20,
    'menu_icon' => 'http://placeholder.com/20x20',
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
'has_archive' => 'prosjekter',
    'query_var' => true,
    'can_export' => true,
'rewrite' => true,
    'capability_type' => 'post'
);

register_post_type( 'prosjekt', $args );
}

/** Custom post 2 (ansatt = employee) **/

add_action( 'init', 'register_cpt_ansatt' );

function register_cpt_ansatt() {

$labels = array( 
    'name' => _x( 'Ansatte', 'ansatt' ),
    'singular_name' => _x( 'Ansatt', 'ansatt' ),
    'add_new' => _x( 'Legg til ny', 'ansatt' ),
    'add_new_item' => _x( 'Legg til ny ansatt', 'ansatt' ),
    'edit_item' => _x( 'Rediger ansatt', 'ansatt' ),
    'new_item' => _x( 'Ny ansatt', 'ansatt' ),
    'view_item' => _x( 'Vis ansatt', 'ansatt' ),
    'search_items' => _x( 'Søk i ansatte', 'ansatt' ),
    'not_found' => _x( 'Ingen ansatte funnet', 'ansatt' ),
    'not_found_in_trash' => _x( 'Ingen ansatte funnet i søppelet', 'ansatt' ),
    'parent_item_colon' => _x( 'Parent Ansatt:', 'ansatt' ),
    'menu_name' => _x( 'Ansatte', 'ansatt' ),
);

$args = array( 
    'labels' => $labels,
    'hierarchical' => false,
    'description' => 'Ansatte',
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'revisions' ),
    'taxonomies' => array( 'post_tag' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 20,
    'menu_icon' => 'http://placeholder.com/20x20',
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => false,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'post'
);

register_post_type( 'ansatt', $args );
}

I have created a single-ansatt.php and single-prosjekt.php, where the single-prosjekt.php works fine, but the single-ansatt.php goes to errorsite – page not found (404).

Is there any logic reason for this to happen?

Related posts

Leave a Reply