2016-12-07 140 views
2

我想能夠將我的WooCommerce產品發佈到我的「帖子」類別中。基於下面的這個鱈魚,這是可能的。這是我在我的functions.php中使用的代碼。當我在Woo製作新產品時,類別是可點擊的,但它不會發布到類別本身。感謝有關此事的任何見解。將類別選擇添加到自定義帖子類型

添加類別選擇自定義後類型

function reg_cat() { 
    register_taxonomy_for_object_type('category','CUSTOM_POST_TYPE'); 
} 
add_action('init', 'reg_cat'); 

回答

0

請試試這個代碼寄存器中的新texonomy

function custom_taxonomy() { 
    register_taxonomy( 
     'custom_categories', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
     'post_type',  //post type name 
     array( 
      'hierarchical' => true, 
      'label' => 'Themes store', //Display name 
      'query_var' => true, 
      'rewrite' => array(
       'slug' => 'themes', // This controls the base slug that will display before each term 
       'with_front' => false // Don't display the category base before 
      ) 
     ) 
    ); 
} 
add_action('init', 'custom_taxonomy'); 

注:請主題function.php添加該代碼或您的插件

============================================= ======== ==================

function reg_cat() { 
     register_taxonomy_for_object_type('category','CUSTOM_POST_TYPE'); 
    } 
add_action('init', 'reg_cat'); 

這段代碼在自定義後類型texonomy部分工作職位類別顯示請參考

enter image description hereenter image description here

+0

正確的,但是在產品發佈ISN」在類別中顯示。它的作品,只是不顯示在類別中。 – SlyMurphy

0

對於註冊自定義分類,你可以試試下面的代碼,更https://codex.wordpress.org/Function_Reference/register_taxonomy

<?php 
add_action('init', 'create_book_tax'); 

function create_book_tax() { 
    register_taxonomy(
     'genre', 
     'book', 
     array(
      'label' => __('Genre'), 
      'rewrite' => array('slug' => 'genre'), 
      'hierarchical' => true, 
     ) 
    ); 
} 
?> 
+0

@SlyMurphy No ... –

相關問題