Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@5c8c1cc from refs/heads/release/5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
prcdevgitbot committed Mar 19, 2024
1 parent 9c2a618 commit 83cbb53
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions blocks/post-taxonomy-terms/post-taxonomy-terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ public function render_block_callback( $attributes, $content, $block ) {
)),
'style' => array_key_exists('separator', $attributes) ? '--separator: "' . $attributes['separator'] . '"' : null,
));

$post_terms = wp_get_post_terms( get_the_ID(), $taxonomy, array( 'number' => $per_page ) );
$post_id = get_the_ID();
$parent_id = wp_get_post_parent_id($post_id);
$post_terms = wp_get_post_terms( $post_id, $taxonomy, array( 'number' => $per_page ) );
// If this is a category taxonomy block we need to check if the only term being returned is "uncategorized" and if so, we need to return an empty array so that the block will look for the parent post's terms, if available.
if ( 'category' === $taxonomy && 1 === count($post_terms) && 'uncategorized' === $post_terms[0]->slug ) {
$post_terms = array();
}
if ( 0 !== $parent_id && empty($post_terms) ) {
$post_terms = wp_get_post_terms( $parent_id, $taxonomy, array( 'number' => $per_page ) );
}
$markup = '';
if ( !empty($post_terms) && !is_wp_error($post_terms) ) {
$markup .= '<ul class="wp-block-prc-block-post-taxonomy-terms__list">';
Expand Down

0 comments on commit 83cbb53

Please sign in to comment.