NEED I have a list of terms of attributes in woocommerce, specifically WRITERS: list of writers name. I want to convert writers name in posts of a custom post type, WRITERS. The terms of attribute woocommerce are around 2000. I would like to automate the insertion.

IDEA Use wp_insert_post and create a loop that inserts the name of the term of the taxonomy as the title of the post. Is it possible?

function convert_attribute_post_type () {
   $terms = get_terms("pa_writers");
   foreach ( $terms as $term ) :

wp_insert_post(array('post_title'=>'$term->name', 'post_type'=>'writers', 'post_content'=>'text'));


Is it possible?


It's definitely possible, I believe you are on the right track.

You might wanna add a check if a post already exists with this title, because you're likely to run into some PHP timeout issues with your script. That way you can run the script several times and create all the posts.

You can use the post_exists() function for this:

if( post_exists( $term->name ) ){
} else {

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.