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'));
endforeach;
}
Is it possible?
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'));
endforeach;
}
Is it possible?
Share Improve this question edited Oct 23, 2018 at 8:36 Antonio Carbone asked Oct 22, 2018 at 18:29 Antonio CarboneAntonio Carbone 216 bronze badges1 Answer
Reset to default 0It'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 ) ){
continue;
} else {
wp_insert_post($args);
}