-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Site Editor: Sort post types alphabetically within the Add Template
modal
#70562
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
Site Editor: Sort post types alphabetically within the Add Template
modal
#70562
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. |
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 think we can move forward with this PR, but we might want to get some additional feedback just to be sure.
The important points are:
- This PR does not sort all templates alphabetically. It only sorts templates related to post types. Non-post type templates have a fixed sort order.
- One thing to note is that the sorting of these templates may change depending on the locale if the labels are translatable.
Thanks for the PR, and thanks for the ping. This gets to the heart of it:
This is an intentional curation both for templates, and for the block library: it is more likely that you'll want to edit your Front-Page template than your Author Archives template. Similarly, it's more likely you'll want to insert an Image than a Details block. This becomes important for translations as well. Since this PR doesn't touch that aspect, it seems fine. |
Similarly I was wondering if single post should always be first, even if there are custom post types? |
This isn't hard, but we'll probably have to hard-code the post type string in the logic. Example code: const usePublicPostTypes = () => {
const postTypes = useSelect(
( select ) => select( coreStore ).getPostTypes( { per_page: -1 } ),
[]
);
return useMemo( () => {
return postTypes
?.filter(
( { viewable, slug } ) => viewable && slug !== 'attachment'
)
.sort( ( a, b ) => {
if ( a.slug === 'post' || b.slug === 'post' ) {
return 0;
}
return a.name.localeCompare( b.name );
} );
}, [ postTypes ] );
}; |
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.
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
Thank you |
… modal (#70562) * fix: sort post types alphabetically * fix: single post should always be first * chore: include comments --------- Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org>
What, Why, and How?
Closes #70558
This PR adds the logic to order
Post Types
using locale-aware string comparison, making it easier for users to find specific post types in the list.Testing Instructions
Example
Appearance -> Editor -> Templates
and click on theAdd Template
button.Archive:
andSingle item:
values are all alphabetically ordered.Testing Instructions for Keyboard
Same.
Screenshots