-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add menu_order sorting option to Query Loop block #68781
base: trunk
Are you sure you want to change the base?
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. |
@@ -75,6 +75,37 @@ export function QueryControls( { | |||
// but instead are destructured inline where necessary. | |||
...props | |||
}: QueryControlsProps ) { | |||
const orderByList = [ |
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.
The name here matches the props.categoriesList
convention used below with orderBy
being the feature.
@@ -23,6 +23,16 @@ const orderOptions = [ | |||
label: __( 'Z → A' ), | |||
value: 'title/desc', | |||
}, | |||
{ |
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.
These options should be available only to post types that support page attributes. Where and how do we add that logic? Here is a reference to how the "order" setting is decided at the page settings three-dots:
gutenberg/packages/editor/src/dataviews/store/private-actions.ts
Lines 156 to 158 in be5ce8a
postTypeConfig.supports?.[ 'page-attributes' ] | |
? reorderPage | |
: undefined, |
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 don't know if it helps but there is a PageAttributesCheck
, that you can take inspiration from:
https://github.com/WordPress/gutenberg/blob/trunk/packages/editor/src/components/page-attributes/check.js
A check for the post type support should probably go in the block's utils.js file.
Thank you for working on this. In the block editor when you edit a page and change the order, the label for the option is just "Order", but "Order by order" is not a helpful label 😆 |
Thank you for reviewing the changeset @carolinan!
Right!? That is why I left it at "menu order" because I couldn't think of a better term that would work equally well between various post types. How about "Sort by manual order" or "Sort by custom order"? |
First, kudos for working on this, @kasparsd. Second, while the dropdown is totally native, I did wonder about bringing the same filtering now in from DataViews and the documentation in Storybook here. I don't want to derail this ticket though. Let's ship good things quickly. I will make another one as I feel some unification can be done. Beyond that, thank you again; it's so great to see. |
Thank you @karmatosed for reviewing the ticket and providing the additional context!
I had the exact same feeling when I saw the ordering options repeated in three different places across the codebase. It feels like there must be some historic context that would explain that and potentially an existing initiative that is working to resolve this. So I'm openly asking for support for (1) how to bring in the contextual availability for the |
It also can't use "Page order" since it can be enabled on other post types. |
Thanks for the additional context @karmatosed! I've updated the labels per your recommendation. I believe this is the best we can do without revisiting the whole "menu order" label across the admin (quick edit, page order configuration, etc.). |
What?
Add the
menu_order
sorting option in addition to post title and date.Why?
Fixes #42710.
Users are able to set a numerical menu order for post types that support it (pages, by default). Smaller values rise to the top while larger values sink to the bottom, as implemented by
WP_Query
ordering.How?
QueryControls
component to includemenu_order
as one of the options.Questions
While the
menu_order
value is available for all post types in the database, only those that register support forpage-attributes
feature will have the setting available. What's the best approach to including themenu_order
option only to post types with the page attributes enabled? Here is how the "Order" gets added conditionally to the dataviews:gutenberg/packages/editor/src/dataviews/store/private-actions.ts
Lines 156 to 158 in be5ce8a
Testing Instructions
Testing Instructions for Keyboard
This change is extending an existing selector so the keyboard navigation remains unchanged.
Screenshots or screencast
Ordering examples with updated preview:
Descending:
Ascending: