I have two Custom Post Types called book and publisher. The book has two Custom Fields (Metabox) author_fname and author_lname and the publisher has a Custom Taxonomy called authors

Now can you please let me know how I can use book metaboxes (author_fname and author_lname) to dynamically create a taxonomy ( authors) term for publisher as soon as the new Custom Post of book is published?

Here is the code I have

function add_cpt_term($post_ID) {
    $post = get_post($post_ID);
    $meta = get_post_custom($post); 
    $mfname = $meta['author_fname'][0];
    $mlname = $meta['author_lname'][0];
if (!term_exists($mfname. " " . $mlname, 'authors'))
        wp_insert_term( $mfname. " " . $mlname, 'authors', array('slug' => $mfname. " " . $mlname));
add_action('publish_book', 'add_cpt_term');

Not Getting any error but it is not publishing any term either

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.