auto custom field to category
-
I found this script to functions
function wpse_248054(){ $custom_field_name = 'Genre'; $posts = new WP_Query( array( 'posts_per_page' => -1, 'post_type'=> 'post', ) ); foreach($posts->posts as $post){ $meta = get_post_meta($post->ID, 'Genre', true); if(! empty( $meta )){ $term_id = wp_create_category($meta, 3); // 2nd argument, parent id (optional) $new_post_cat = wp_set_post_terms( $post->ID, $term_id, 'category', true ); } } } add_action('admin_init', 'wpse_248054');
this auto add custom field to category, the problem is the meta key have a multiple values, like : Action, Drama, War
and this script don’t separate values with comma and creat a category “Action, Drama, War” all together. who can i separate values ?
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘auto custom field to category’ is closed to new replies.