首页 文章

如何在自定义帖子类型中添加WooCommerce产品类别

提问于
浏览
1
$args = array(
    'label'               => __( 'Eventr', 'dnp_theme' ),
    'description'         => __( 'What clients say ', 'dnp_theme' ),
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', 'thumbnail'),
    'taxonomies'          => array( 'Eventr', 'product_cat'),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => false,
    'show_in_admin_bar'   => true,
    'menu_position'       => 10,
    'menu_icon'           => 'dashicons-images-alt2',
    'can_export'          => true,
    'has_archive'         => false,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'post',
);

register_post_type( 'Eventr', $args );

这是我的代码用于在我的自定义帖子类型中获取Woocommerce产品类别 .

在Taxonomies中,我添加了woocommerce产品类别分类“product_cat”,但它不会显示在管理面板上 .

帮助我了解如何在自定义帖子类型管理员菜单中添加WooCommerce产品类别 .

1 回答

  • 4

    我遇到了同样的问题,我发现之后注册分类法似乎有效 . 因此,在注册自定义帖子类型后的函数中,添加类似这样的内容,其中 custom_post_type key是您注册的密钥:

    add_action( 'init', 'add_product_cat_to_custom_post_type' ); function add_product_cat_to_custom_post_type() { register_taxonomy_for_object_type( 'product_cat', 'custom_post_type' ); }

相关问题