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.
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:
-
I can’t work out how to call all the metadata associated with each
$term
. -
How can I then pass each piece of metadata into each post?
I’ve solved this myself using a fairly basic (and pretty hacky) solution in the form of a plugin. It is shared as a Gist if anyone runs into the same issue as me: https://gist.github.com/Strap1/8053824