diff --git a/packages/playground/blueprints/src/lib/steps/import-wxr.ts b/packages/playground/blueprints/src/lib/steps/import-wxr.ts index 1b6611526e..1169d133d3 100644 --- a/packages/playground/blueprints/src/lib/steps/import-wxr.ts +++ b/packages/playground/blueprints/src/lib/steps/import-wxr.ts @@ -59,6 +59,25 @@ export const importWxr: StepHandler> = async ( return wp_slash($data); }); + // Ensure that Site Editor templates are associated with the correct taxonomy. + add_filter( 'wp_import_post_terms', function ( $terms, $post_id ) { + foreach ( $terms as $post_term ) { + if ( 'wp_theme' !== $term['taxonomy'] ) continue; + $post_term = get_term_by('slug', $term['slug'], $term['taxonomy'] ); + if ( ! $post_term ) { + $post_term = wp_insert_term( + $term['slug'], + $term['taxonomy'] + ); + $term_id = $post_term['term_id']; + } else { + $term_id = $post_term->term_id; + } + wp_set_object_terms( $post_id, $term_id, $term['taxonomy']) ; + } + return $terms; + }, 10, 2 ); + $result = $importer->import( '/tmp/import.wxr' ); `, });