Taxonomies: Term order not retained (if sort
is true
)
#65052
Labels
[Status] In Progress
Tracking issues with work in progress
[Type] Bug
An existing feature does not function as intended
Description
For any taxonomy registered via
register_taxonomy
that hasshow_in_rest
set totrue
, the block editor automatically adds a panel to the sidebar that allows editing the terms associated with the current post. (The UI is the same that's used for WP's built-in categories and tags, respectively -- for hierarchical and non-hierarchical ("flat") taxonomies, respectively.)When the user edits any of those flat taxonomy terms, they are always sorted alphabetically. This might be fine for Tags; however,
register_taxonomy
includes an argument calledsort
, which, if set totrue
, is supposed to retain the order in which terms are added by the user. This is currently being ignored.--
There's a workaround, which consists in setting
'args' => array( 'orderby' => 'term_order' )
upon registering the taxonomy. This forcibly sets the sort order toterm_order
in any query for the taxonomy. But arguably, this workaround shouldn't be needed; setting'sort' => true
should be enough.Step-by-step reproduction instructions
Add the following code (e.g. to your theme's
functions.php
) and use the "Actors" panel in the block inspector to assign a number of actor names to a given post. Note that the actors are re-ordered alphabetically every time a new actor is added. Try saving and reloading the post, and view it on the frontend, and note that the actors also appear in alphabetical order there.Screenshots, screen recording, code snippet
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
The text was updated successfully, but these errors were encountered: