[ [ 'name' => 'Catégorie 1', 'slug' => 'cat-1', 'parent' => false, 'description' => 'C’est ma catégorie', 'meta' => [ 'extId' => '12' ], // new ], [ 'name' => 'Catégorie 2', 'slug' => 'cat-2', 'parent' => 'cat-1', 'description' => 'C’est ma sous-catégorie', 'meta' => [ 'extId' => '14', 'old_uri' => '/categorie/foo/bar/' ], // new ], ] ]; foreach ( $taxonomies as $tax => $terms ) { foreach ( $terms as $term ) { if ( $term['parent'] && $parent = term_exists( $term['parent'], $tax ) ) { $term['parent'] = $parent['term_id']; } $t = wp_insert_term( $term['name'], $tax, $term ); // -> add meta if ( is_wp_error( $t ) ) return false; if ( ! empty( $term['meta'] ) ) { foreach ( $term['meta'] as $key => $meta ) { update_term_meta( $t['term_id'], $key, $meta ); } } } }