2016-12-07 145 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 ... –

相关问题