• Resolved frafor

    (@frafor)


    Hi there,

    I have two custom post types, say:

    Labels
    Artists

    Artists has its own taxonomy, called again Label.

    I would like to automatically create a term, within this taxonomy, for each post title present in the CPT Labels.

    In this way, if i create a post titled “My Own Record” in Labels, then i’ll get even “My Own Record” as a term within Artists’s taxonomy “Label”.

    How can i get this? I’ve made some search, but i couldn’t find anything similar.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter frafor

    (@frafor)

    SOLVED! In theme functions.php ??

    function add_new_term() {
        $args = array(
            'posts_per_page'    =>  -1,
            'post_type'         =>  'labels'
        );
        $title_query = get_posts('numberposts=-1&post_type=labels');
    
    	foreach ($title_query as $single_post) {
    
    		$title = get_the_title($single_post->ID);
    		$taxonomy = 'label';
    		$exist = term_exists($title, $taxonomy);
    
    			if ( $exist == FALSE )
    				{
    				wp_insert_term($title, 'label');
    
    		}
    }
    }
    add_action('init','add_new_term');

    Thread Starter frafor

    (@frafor)

    Forgot to mark as solved…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Auto term creation in a specific taxonomy according to a defined CPT post title’ is closed to new replies.