Reputation: 155
I wanna be able to post my WooCommerce products into my "posts" categories. Based based off this cod below, it's possible. Here's the code I'm using in my functions.php. The categories are clickable when I make a new product in Woo however, it's not posting to the category itself. Appreciate any insight on this matter.
Add category selection to custom post type
function reg_cat() {
register_taxonomy_for_object_type('category','CUSTOM_POST_TYPE');
}
add_action('init', 'reg_cat');
Upvotes: 2
Views: 2000
Reputation: 1357
Please try This Code for register new 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');
Note: Please add this code in theme function.php or your plugin
=======================================================================
function reg_cat() {
register_taxonomy_for_object_type('category','CUSTOM_POST_TYPE');
}
add_action('init', 'reg_cat');
This code working post category display in custom post type texonomy section Please refer
Upvotes: 0
Reputation: 2928
For register custom taxonomy you can try below code, for more 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,
)
);
}
?>
Upvotes: 0