diff --git a/wp-modules/editor/editor.php b/wp-modules/editor/editor.php index 18821f978..af1ca254a 100644 --- a/wp-modules/editor/editor.php +++ b/wp-modules/editor/editor.php @@ -174,6 +174,24 @@ function register_pattern_post_type() { 'default' => get_pattern_defaults()['keywords'], ) ); + + register_post_meta( + $post_type_key, + 'customCategories', + array( + 'show_in_rest' => array( + 'schema' => array( + 'type' => 'array', + 'items' => array( + 'type' => 'string', + ), + ), + ), + 'single' => true, + 'type' => 'array', + 'default' => [], + ) + ); } add_action( 'init', __NAMESPACE__ . '\register_pattern_post_type' ); diff --git a/wp-modules/editor/js/src/components/PatternManagerMetaControls/index.tsx b/wp-modules/editor/js/src/components/PatternManagerMetaControls/index.tsx index 9052b73c5..fc16fa1c1 100644 --- a/wp-modules/editor/js/src/components/PatternManagerMetaControls/index.tsx +++ b/wp-modules/editor/js/src/components/PatternManagerMetaControls/index.tsx @@ -49,6 +49,7 @@ export default function PatternManagerMetaControls() { & +}: BaseSidebarProps< 'categories' | 'customCategories' > & AdditionalSidebarProps< 'categoryOptions' > ) { + // The list of currently selected categories, formatted for react-select. + const selectedCategories: typeof categoryOptions = categories.reduce( + ( acc, categoryName ) => + ! acc.includes( categoryName ) + ? [ + ...acc, + categoryOptions.find( + ( matchedCategory ) => + matchedCategory.value === categoryName + ), + ] + : acc, + [] + ); + return ( { categoryOptions ? ( -