diff --git a/lib/blocks.php b/lib/blocks.php
index 2d0b969cc6b19..7bd7763e7b497 100644
--- a/lib/blocks.php
+++ b/lib/blocks.php
@@ -73,25 +73,26 @@ function gutenberg_reregister_core_block_types() {
$block_names = array_merge(
$block_names,
array(
- 'post-author.php' => 'core/post-author',
- 'post-comment.php' => 'core/post-comment',
- 'post-comment-content.php' => 'core/post-comment-content',
- 'post-comments.php' => 'core/post-comments',
- 'post-comments-count.php' => 'core/post-comments-count',
- 'post-comments-form.php' => 'core/post-comments-form',
- 'post-content.php' => 'core/post-content',
- 'post-date.php' => 'core/post-date',
- 'post-excerpt.php' => 'core/post-excerpt',
- 'post-featured-image.php' => 'core/post-featured-image',
- 'post-tags.php' => 'core/post-tags',
- 'post-title.php' => 'core/post-title',
- 'query.php' => 'core/query',
- 'query-loop.php' => 'core/query-loop',
- 'query-pagination.php' => 'core/query-pagination',
- 'site-logo.php' => 'core/site-logo',
- 'site-tagline.php' => 'core/site-tagline',
- 'site-title.php' => 'core/site-title',
- 'template-part.php' => 'core/template-part',
+ 'post-author.php' => 'core/post-author',
+ 'post-comment.php' => 'core/post-comment',
+ 'post-comment-content.php' => 'core/post-comment-content',
+ 'post-comments.php' => 'core/post-comments',
+ 'post-comments-count.php' => 'core/post-comments-count',
+ 'post-comments-form.php' => 'core/post-comments-form',
+ 'post-content.php' => 'core/post-content',
+ 'post-date.php' => 'core/post-date',
+ 'post-excerpt.php' => 'core/post-excerpt',
+ 'post-featured-image.php' => 'core/post-featured-image',
+ 'post-hierarchical-terms.php' => 'core/post-hierarchical-terms',
+ 'post-tags.php' => 'core/post-tags',
+ 'post-title.php' => 'core/post-title',
+ 'query.php' => 'core/query',
+ 'query-loop.php' => 'core/query-loop',
+ 'query-pagination.php' => 'core/query-pagination',
+ 'site-logo.php' => 'core/site-logo',
+ 'site-tagline.php' => 'core/site-tagline',
+ 'site-title.php' => 'core/site-title',
+ 'template-part.php' => 'core/template-part',
)
);
}
diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js
index e0733e8dc1231..ac2ae4d759d56 100644
--- a/packages/block-library/src/index.js
+++ b/packages/block-library/src/index.js
@@ -83,6 +83,7 @@ import * as postCommentsForm from './post-comments-form';
import * as postDate from './post-date';
import * as postExcerpt from './post-excerpt';
import * as postFeaturedImage from './post-featured-image';
+import * as postHierarchicalTerms from './post-hierarchical-terms';
import * as postTags from './post-tags';
/**
@@ -218,6 +219,7 @@ export const __experimentalRegisterExperimentalCoreBlocks =
postDate,
postExcerpt,
postFeaturedImage,
+ postHierarchicalTerms,
postTags,
]
: [] ),
diff --git a/packages/block-library/src/post-hierarchical-terms/block.json b/packages/block-library/src/post-hierarchical-terms/block.json
new file mode 100644
index 0000000000000..0afec0b02857a
--- /dev/null
+++ b/packages/block-library/src/post-hierarchical-terms/block.json
@@ -0,0 +1,26 @@
+{
+ "name": "core/post-hierarchical-terms",
+ "category": "design",
+ "attributes": {
+ "term": {
+ "type": "string"
+ },
+ "textAlign": {
+ "type": "string"
+ }
+ },
+ "usesContext": [
+ "postId",
+ "postType"
+ ],
+ "supports": {
+ "html": false,
+ "lightBlockWrapper": true,
+ "__experimentalFontSize": true,
+ "__experimentalColor": {
+ "gradients": true,
+ "linkColor": true
+ },
+ "__experimentalLineHeight": true
+ }
+}
diff --git a/packages/block-library/src/post-hierarchical-terms/edit.js b/packages/block-library/src/post-hierarchical-terms/edit.js
new file mode 100644
index 0000000000000..dbc4da3060844
--- /dev/null
+++ b/packages/block-library/src/post-hierarchical-terms/edit.js
@@ -0,0 +1,143 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+import { find } from 'lodash';
+
+/**
+ * WordPress dependencies
+ */
+import {
+ AlignmentToolbar,
+ BlockControls,
+ Warning,
+ __experimentalBlock as Block,
+ __experimentalBlockVariationPicker as BlockVariationPicker,
+} from '@wordpress/block-editor';
+import { Spinner } from '@wordpress/components';
+import { useSelect } from '@wordpress/data';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import useHierarchicalTermLinks from './use-hierarchical-term-links';
+
+export default function PostHierarchicalTermsEdit( {
+ attributes,
+ clientId,
+ context,
+ name,
+ setAttributes,
+} ) {
+ const { term, textAlign } = attributes;
+ const { postId, postType } = context;
+
+ const { blockType, defaultVariation, variations } = useSelect(
+ ( select ) => {
+ const {
+ getBlockVariations,
+ getBlockType,
+ getDefaultBlockVariation,
+ } = select( 'core/blocks' );
+
+ return {
+ blockType: getBlockType( name ),
+ defaultVariation: getDefaultBlockVariation( name, 'block' ),
+ variations: getBlockVariations( name, 'block' ),
+ };
+ },
+ [ clientId, name ]
+ );
+
+ const selectedTerm = useSelect(
+ ( select ) => {
+ if ( ! term ) return {};
+ const taxonomies = select( 'core' ).getTaxonomies( {
+ per_page: -1,
+ } );
+ return (
+ find(
+ taxonomies,
+ ( taxonomy ) =>
+ taxonomy.slug === term &&
+ taxonomy.hierarchical &&
+ taxonomy.visibility.show_ui
+ ) || {}
+ );
+ },
+ [ term ]
+ );
+
+ const {
+ hierarchicalTermLinks,
+ isLoadingHierarchicalTermLinks,
+ } = useHierarchicalTermLinks( {
+ postId,
+ postType,
+ term: selectedTerm,
+ } );
+
+ const hasPost = postId && postType;
+ const hasHierarchicalTermLinks =
+ hierarchicalTermLinks && hierarchicalTermLinks.length > 0;
+
+ if ( ! hasPost ) {
+ return (
+