How can I convert a Custom Taxonomy to a Custom Post Type?

I’ve not been able to find any information on this – a bit of an unusual request.

I’ve decided I’m best off creating a Custom Post Type to handle my database of Artists and Albums on my music site, currently stored as a Custom Taxonomy. There’s clearly more flexibility in CPTs than Taxonomies. I’m going to use Scribu’s Posts2Posts plugin to connect my current CPTs (Videos, Lyrics, Reviews etc) with the Artists and Albums CPTs.

Read More

Since I have a large-ish quantity in my Artists Taxonomy including lots of meta data, I’m looking for a way to carry the data to a CPT (and corresponding Meta Fields) – too much to do by hand.

Has anyone else got this issue, and has anyone got a solution?

UPDATE:
I’m writing a function that I hope will achieve what I need. I’m a bit stuck however.

function make_posts_from_taxonomy($taxonomy, $post_type) {
// Get all Taxonomy
$args = array(
'parent' => 0
);

$taxonomy = 'hhie_artists';
$post_type = 'hhie_artists';

$terms = get_terms( $taxonomy, $args);

foreach ($terms as $term) {
    get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    $id = $term->ID;
    $name = $term->name; //Title
    $slug = $term->slug; //Slug
    $description = $term->description; //Description

$new_post = array(  
        'post_title' => $name,
        'post_content' => $description,
        'post_name' => $slug,
        'post_type' => $post_type,
    );
    //Insert post
    wp_insert_post ($new_post);

    } //End foreach

} //End function

This has worked. I’ve been able to create the new CPT posts.
Remaining issues:

  1. I can’t work out how to call all the metadata associated with each $term.

  2. How can I then pass each piece of metadata into each post?

Related posts

1 comment

Comments are closed.