Opened 7 years ago
Last modified 6 weeks ago
#49194 reviewing defect (bug)
Page Template dropdown ordering should be by title, not value
| Reported by: | leec87 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Posts, Post Types | Version: | |
| Severity: | minor | Keywords: | good-first-bug has-test-info has-patch |
| Cc: | Focuses: | ui, administration |
Description
The ordering of items within the Page Template dropdown field is sorted by the value alphabetically, which often creates what appears to be an unordered display when viewing on the front end.
I this should be changed so the ordering of the dropdown options is based on the alphabetical order of the list items themselves.
Attachments (4)
Change History (13)
#1
@
7 years ago
- Component General → Posts, Post Types
- Focuses ui administration added; accessibility removed
This ticket was mentioned in Slack in #core by sirlouen. View the logs.
10 months ago
#3
@
10 months ago
- Keywords good-first-bug needs-patch has-test-info added
- Milestone Awaiting Review → Future Release
- Type enhancement → defect (bug)
#4
@
10 months ago
Proposed patch sorts page templates by their human-readable name before flipping the array, ensuring UI ordering by template name, patch file uploaded.
#5
@
10 months ago
- Keywords has-patch added; needs-patch removed
- Owner set to
- Status new → reviewing
Thanks @johnnycocheroo454 I will be reviewing it asap.
#7
@
4 months ago
Test Report
Description
This report validates whether the indicated patch works as expected.
The patch tested was johnnycocheroo454 from @johnnycocheroo454
I tried applying 49194-sort-page-templates-by-title.patch but it failed. The modified file is not the same as in the patch.
Patch tested: https://core.trac.wordpress.org/ticket/49194
Environment
- WordPress: 7.0-beta2-20260305.115512
- PHP: 8.2.27
- Server: nginx/1.26.1
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.2.27)
- Browser: Firefox 148.0
- OS: Linux
- Theme: Twenty ten
- MU Plugins: None activated
- Plugins: None
- Test Reports 1.2.1
Actual Results
- ❌ Failed : The list was still following the value and not the name.
Additional Notes
- Any additional details worth mentioning.
Supplemental Artifacts
Screen captures here : https://imgur.com/a/N92QM9c
This ticket was mentioned in PR #11955 on WordPress/wordpress-develop by @kazisadibreza.
8 weeks ago
#8
Sorted the resolved page and block template arrays alphabetically by their human-readable, translated titles using a case-insensitive uasort() loop. This resolves an issue where templates were being returned based on raw filesystem file discovery sorting orders, causing mismatched structural dropdown hierarchies in the editor interface UI.
Trac ticket: https://core.trac.wordpress.org/ticket/49194
## Use of AI Tools
AI assistance: Yes
Tool(s): Gemini
Model(s): Gemini 1.5 Pro
Used for: Identifying legacy variable extraction errors and structuring the uasort callback implementation within the get_post_templates() method context.
@
6 weeks ago
Patch to sort post templates by translated, human-readable template name instead of filename/slug, with PHPUnit test coverage.
#9
@
6 weeks ago
Added 49194-sort-post-templates-by-title.diff.
This takes the same approach as the existing PR by sorting the resolved $post_templates arrays after translation and after custom block templates are merged, but simplifies the callback to use strnatcasecmp directly.
The patch also adds PHPUnit test coverage to confirm templates are sorted by their human-readable template labels while preserving the original template keys.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Reproduction Report
Description
✅ This report validates that the issue can be reproduced.
Environment
Testing Instructions
a-template.php,b-template.php,c-template.phpget_page_templatesActual Results
Supplemental Artifacts
Added this to functions.php:
function page_templates_admin_menu() { add_menu_page( 'Page Templates', 'Page Templates', 'manage_options', 'page-templates', 'page_templates_admin_page', 'dashicons-media-code', 81 ); } add_action( 'admin_menu', 'page_templates_admin_menu' ); function show_page_templates() { } function page_templates_admin_page() { $templates = get_page_templates(); echo '<div>'; echo '<h1>Page Templates</h1>'; echo '<ul>'; foreach ( $templates as $filename => $name ) { echo '<li>' . $name . ' (' . $filename . ')</li>'; } echo '</ul>'; echo '</div>'; }