Dynamically Create Terms in Taxonomy when Custom Post Type is Published. Almost There!

You’re almost there – the problem is you’re trying to access the $post object when the function only receives the post ID.

add_action( 'publish_country', 'add_country_term' );
function add_country_term( $post_ID ) {
    $post = get_post( $post_ID ); // get post object
    wp_insert_term( $post->post_title, 'country_taxo' );
}

Leave a Comment