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 (#1997)

Fixes #1996 

While the bug might be in the WordPress-Importer itself, we can fix it
by adding a filter that just ensures that the term will be created. I
vote for adding this small intermediate fix even as in #1888 there is
the plan to import WXRs differently in future. This is confusing
behavior right now and we can fix it
  • Loading branch information
akirk authored Dec 10, 2024
1 parent 0314ce5 commit 2b00b04
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 2b00b04

Please sign in to comment.