最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish

programmeradmin2浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论