admin管理员组文章数量:1130349
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);
}
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);
}
本文标签: Convert attribute woocommerce terms (taxonomy terms) in posts of custom post type
版权声明:本文标题:Convert attribute woocommerce terms (taxonomy terms) in posts of custom post type 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749239626a2337861.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论