Query Title: Add "Post Type Label" variation#71167
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| export function usePostTypeLabel( contextPostType ) { | ||
| const currentPostType = useSelect( ( select ) => { | ||
| // eslint-disable-next-line @wordpress/data-no-store-string-literals | ||
| const { getCurrentPostType } = select( 'core/editor' ); |
There was a problem hiding this comment.
Can we import the store name here instead of suppressing the eslint error?
There was a problem hiding this comment.
Thank you for the review!
I did this to avoid having @wordpress/editor as a dependency for @wordpress/block-editor. A similar pattern is used in useArchiveLabel:
Would it help if I add a comment referencing this?
There was a problem hiding this comment.
I would add the reference, yes. That way there is no confusion for reviewers or other engineers who reference this code. Thanks for the explanation!
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR! I left some minor feedback, but I think the overall approach is correct.
I also understand that for this block to work outside of a query context, we have to hard-code the editor store name.
t-hamano
left a comment
There was a problem hiding this comment.
LGTM!
Note that failing tests aren't related to this PR. They're a temporary problem related to the .org server. See: https://wordpress.slack.com/archives/C02QB2JS7/p1755184038359589
|
Can we add support for paragaph-tag for the block? |
|
@Drivingralle I think it's possible. Please feel free to submit an issue. |
What?
Closes #55949
This PR adds a "Post Type Label" variation to the
core/query-titleblock, which displays the singular name of the queried post type.Why?
Currently, there’s no way to dynamically display the post type label in a query context. This variation extends
core/query-titleto support built-in and custom post types.How?
Testing Instructions
Screenshots or screencast
Using "Post Type Label" under each post title to show the queried post type (with and without prefix).