2017-04-23 42 views
0

這使我瘋狂。自定義帖子類型slu conflicts與另一種帖子類型衝突

我有兩個自定義文章類型

register_post_type('products', 
    array(
     'labels' => array(
      'name' => __('Products'), 
      'singular_name' => __('Product') 
     ), 
     'public' => true, 
     'has_archive' => true, 
     'rewrite' => array('slug' => 'products'), 
    ) 
); 

register_post_type('markets', 
    array(
     'labels' => array(
      'name' => __('Markets'), 
      'singular_name' => __('Market') 
     ), 
     'public' => true, 
     'has_archive' => true, 
     'rewrite' => array('slug' => 'markets'), 
    ) 
); 

和兩個模板(歸檔products.php和歸檔markets.php)

products自定義類型的作品。存檔頁面正確顯示,但單個頁面不顯示。如果我刪除市場上的register_post_type,則產品的單頁工作。

但是,markets類型的網址爲www.website.com/products/a-market-post這真的很奇怪,因爲它使用產品帖子類型中的slu g。

有誰知道可能發生了什麼?我刷新了固定鏈接頁面1000次,並沒有做任何事情。

乾杯!

+0

什麼是您的永久鏈接結構? –

+0

你在哪裏放置代碼?在一個函數在init鉤子上觸發? –

+0

@MohammadAshiqueAli月份和名稱 – Splurtcake

回答

0

您錯過了「分類法」。
而你不需要「重寫」,因爲你的slu remains不變。

function manufacturers_posts() { 
    $labels = array(
     'name'    => _x('Products', 'post type general name'), 
     'singular_name'  => _x('Product', 'post type singular name'), 
     'add_new'   => _x('Add new', 'book'), 
     'add_new_item'  => __('Add new product'), 
     'edit_item'   => __('Edit'), 
     'new_item'   => __('יAdd new'), 
     'all_items'   => __('Show all'), 
     'view_item'   => __('Show'), 
     'search_items'  => __('Search'), 
     'not_found'   => __('No products found'), 
     'not_found_in_trash' => __('Trash is empty'), 
     'parent_item_colon' => '', 
     'menu_name'   => 'Products' 
    ); 

    $args = array(
     'labels'  => $labels, 
     'public'  => true, 
     'supports'  => array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'revisions', 'custom-fields', 'tags'), 
     'has_archive' => true, 
     'taxonomies' => array('post_tag') 
    ); 

    register_post_type('manufacturers', $args); 
} 

function manufacturers_taxonomy() { 
    register_taxonomy(
     'manufacturers_taxonomy',     //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
     'manufacturers',        //post type name 
     array(
      'hierarchical' => true, 
      'label' => 'Products',      //Display name 
      'query_var' => true, 
      'has_archive' => 'manufacturers', 
      'rewrite' => array(
       'slug' => 'manufacturers-archive', // This controls the base slug that will display before each term 
       'with_front' => false    // Don't display the category base before 
      ) 
     ) 
    ); 
} 

    add_action('init', 'manufacturers_taxonomy'); 
    add_action('init', 'manufacturers_posts');