Skip to content

Commit

Permalink
Ensure that Site Editor templates are associated with the correct tax…
Browse files Browse the repository at this point in the history
…onomy
  • Loading branch information
akirk committed Nov 14, 2024
1 parent 13cd12a commit 5b13ae0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/playground/blueprints/src/lib/steps/import-wxr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ export const importWxr: StepHandler<ImportWxrStep<File>> = 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' );
`,
});
Expand Down

0 comments on commit 5b13ae0

Please sign in to comment.