2010-09-08 36 views
0

我有一些Wordpress CPT。他們正確的URL應該是/ wordpress/training/training-page /,這就是我在管理管理頁面看到的URL,但是當我點擊鏈接時,我最終得到的URL是/ wordpress/blog/2010/05/21 /培訓頁/。自定義文章類型URL重定向錯了

我停用了我的插件沒有成功。有誰知道如何保持正確的URL完好?

這裏是我的代碼:

<?php 
add_action('init', 'tv_content_posttype'); 
function tv_content_posttype() { 
register_taxonomy('content', 
    'training', 
    array(
     'hierarchical' => true, 
     'label' => 'Content Index', 
     'query_var' => true, 
     'rewrite' => true 
    ) 
); 

register_post_type('training', 
    array(
     'type' => 'page', 
     'labels' => array(
      'name' => __('TV Training'), 
      'singular_name' => __('TV Training') 
     ), 
     'public' => true, 
     'rewrite' => array(
      'with_front' => false, 
      'slug' => 'training', 
     ), 
     'hierarchical' => true, 
     'query_var' => true, 
     'taxonomies' => array('content'), 
    ) 
); 
} 

回答

1

就在幾個意見:有一個'type'論據register_post_type()沒有這樣的事情,這樣你就可以擺脫線。其次,'with_front' => false告訴WordPress,URL結構應該是/training/training-page//wordpress/在這個isntance是你告訴它離開的'前'部分。此外,您不需要爲post_type添加「分類法」,但是在註冊分類標準之前您需要註冊帖子類型。所以試試這個:

<?php 
add_action('init', 'tv_content_posttype'); 
function tv_content_posttype() { 
register_post_type('training', 
    array(
     'labels' => array(
      'name' => __('TV Training'), 
      'singular_name' => __('TV Training') 
     ), 
     'public' => true, 
     'rewrite' => array(
      'with_front' => true, 
      'slug' => 'training', 
     ), 
     'hierarchical' => true, 
     'query_var' => true, 
    ) 
); 

register_taxonomy('content', 
    'training', 
    array(
     'hierarchical' => true, 
     'label' => 'Content Index', 
     'query_var' => true, 
     'rewrite' => true 
    ) 
); 

}