diff --git a/packages/block-library/src/post-hierarchical-terms/edit.js b/packages/block-library/src/post-hierarchical-terms/edit.js index ce0df119b1979f..dbc4da3060844e 100644 --- a/packages/block-library/src/post-hierarchical-terms/edit.js +++ b/packages/block-library/src/post-hierarchical-terms/edit.js @@ -86,7 +86,7 @@ export default function PostHierarchicalTermsEdit( { return ( - { __( 'Post Categories block: post not found.' ) } + { __( 'Post Hierarchical Terms block: post not found.' ) } ); diff --git a/packages/block-library/src/post-hierarchical-terms/index.php b/packages/block-library/src/post-hierarchical-terms/index.php index 73e23b5889ade2..0a153b7958e0a1 100644 --- a/packages/block-library/src/post-hierarchical-terms/index.php +++ b/packages/block-library/src/post-hierarchical-terms/index.php @@ -11,39 +11,39 @@ * @param array $attributes Block attributes. * @param string $content Block default content. * @param WP_Block $block Block instance. - * @return string Returns the filtered post categories for the current post wrapped inside "a" tags. + * @return string Returns the filtered post hierarchical terms for the current post wrapped inside "a" tags. */ function render_block_core_post_hierarchical_terms( $attributes, $content, $block ) { - if ( ! isset( $block->context['postId'] ) ) { + if ( ! isset( $block->context['postId'] ) || ! isset( $attributes['term'] ) ) { return ''; } - $post_categories = get_the_category( $block->context['postId'] ); - if ( empty( $post_categories ) ) { + $post_hierarchical_terms = get_the_terms( $block->context['postId'], $attributes['term'] ); + if ( empty( $post_hierarchical_terms ) ) { return ''; } $align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}"; - $category_links = ''; - foreach ( $post_categories as $category ) { - $category_links .= sprintf( + $terms_links = ''; + foreach ( $post_hierarchical_terms as $term ) { + $terms_links .= sprintf( '%2$s | ', - get_category_link( $category->term_id ), - esc_html( $category->name ) + get_term_link( $term->term_id ), + esc_html( $term->name ) ); } - $category_links = trim( $category_links, ' | ' ); + $terms_links = trim( $terms_links, ' | ' ); return sprintf( '
%2$s
', 'wp-block-post-hierarchical-terms' . esc_attr( $align_class_name ), - $category_links + $terms_links ); } /** - * Registers the `core/post-categories` block on the server. + * Registers the `core/post-hierarchical-terms` block on the server. */ function register_block_core_post_hierarchical_terms() { register_block_type_from_metadata(