0
votes

I want to automatically create custom taxonomy items from the title of custom post type whenever a post is created. The CPT title is Hotel, and the taxonomy name is HotelCategory Example: CPT Name: Hotel LakeView when created automatically creates a custom taxonomy item named: Hotel LakeView. I have been finding the answers with no luck. Please help. Thank you in advance.

1

1 Answers

0
votes

Please add below code in function.php

add_action( 'publish_{post_type_name}', 'add_hotel_term' );

function add_hotel_term( $post_ID ) {

    $post = get_post( $post_ID ); // get post object

    wp_insert_term( $post->post_title, 'HotelCategory' );
}

Hope it help!