Site icon Experience Wordpress Developer Online – Design Develop and Maintenance Support

Register New Taxonomy or Assign existing Taxonomy to Custom Post Type

// Register New taxonomy for existing CUSTOM POST TYPE
add_action('init', 'wdo_tag_for_cpt_post_type');
function wdo_tag_for_cpt_post_type(){
    //register taxonomy for custom post type
    register_taxonomy( 
    'your_taxomony_name', //taxonomy 
    'your_post_type', //post-type for which registering Taxomony
    array( 
        'hierarchical'  => false, 
        'label'         => __( 'Tags','taxonomy general name'), 
        'singular_name' => __( 'Tag', 'taxonomy general name' ), 
        'rewrite' => array( 'slug' => 'your_taxonomy_slug' ),
        'query_var'     => true 
    ));
}
// Assign existing taxonomy to Already registered Custom Post Type
add_action( 'init', 'fn_assign_existing_taxonomy_to_cpt' );
function fn_assign_existing_taxonomy_to_cpt() {
    register_taxonomy_for_object_type( 'post_tag', 'custom_post_type' );
};
Exit mobile version