-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Query Title: Add "Post Type Label" variation #71167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we import the store name here instead of suppressing the eslint error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
:
// @wordpress/block-library should not depend on @wordpress/editor. | |
// Blocks can be loaded into a *non-post* block editor, so to avoid | |
// declaring @wordpress/editor as a dependency, we must access its | |
// store by string. | |
// The solution here is to split WP specific blocks from generic blocks. | |
// eslint-disable-next-line @wordpress/data-no-store-string-literals | |
const { getCurrentPostId, getCurrentPostType, getCurrentTemplateId } = | |
select( 'core/editor' ); |
Would it help if I add a comment referencing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-title
block, 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-title
to 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).