Skip to content

Commit

Permalink
Fix/tag id mismatch (#112)
Browse files Browse the repository at this point in the history
* Allow the use of tag slugs in the wp:query block

* Use tag slug instead of id so it survives export
  • Loading branch information
tellyworth authored Dec 8, 2021
1 parent 47021df commit aa8d2ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:query {"query":{"perPage":5,"postType":"post","tagIds":[14]},"tagName":"section","className":"front__people-of-wordpress","align":"full"} -->
<!-- wp:query {"query":{"perPage":5,"postType":"post","tag":"people-of-wordpress"},"tagName":"section","className":"front__people-of-wordpress","align":"full"} -->
<section class="front__people-of-wordpress alignfull">
<!-- wp:heading {"level":2} -->
<h2>People of WordPress</h2>
Expand Down
7 changes: 7 additions & 0 deletions source/wp-content/themes/wporg-news-2021/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ function custom_query_block_attributes( $parsed_block ) {
$parsed_block[ 'attrs' ][ 'query' ][ 'categoryIds' ] = [ $category->term_id ];
}
}
if ( isset( $parsed_block[ 'attrs' ][ 'query' ][ 'tag' ] ) ) {
$tag = get_term_by( 'slug', $parsed_block[ 'attrs' ][ 'query' ][ 'tag' ], 'post_tag' );
if ( $tag ) {
$parsed_block[ 'attrs' ][ 'query' ][ 'tagIds' ] = [ $tag->term_id ];
}

}
}

return $parsed_block;
Expand Down

0 comments on commit aa8d2ad

Please sign in to comment.