1

我创建了两个自定义帖子类型,第一个工作正常,但第二个最终成为 404 - 找不到页面。我不知道为什么会这样,对我来说这似乎不合逻辑......

这是代码:

/** 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 );
}

我创建了一个single-ansatt.phpsingle-prosjekt.php,其中single-prosjekt.php工作正常,但是single-ansatt.php进入错误站点 - 找不到页面 (404)。

发生这种情况有任何逻辑原因吗?

4

0 回答 0