$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Convert attribute woocommerce terms (taxonomy terms) in posts of custom post type|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Convert attribute woocommerce terms (taxonomy terms) in posts of custom post type

matteradmin10PV0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

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 ) ){
   continue;
} else {
   wp_insert_post($args);
}
Post a comment

comment list (0)

  1. No comments so far