-
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.
packages/block-library/src/query/edit/inspector-controls/order-control.js
Outdated
Show resolved
Hide resolved
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.). |
Duplicate: #51290 |
Thanks for finding the prior attempts at this @carolinan! I've responded inline #51290 with the requirements for the custom order availability. |
packages/block-library/src/query/edit/inspector-controls/order-control.js
Outdated
Show resolved
Hide resolved
function OrderControl( { | ||
order, | ||
orderBy, | ||
orderByOptions = defaultOrderByOptions, |
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.
We're keeping the defaults as fallback to prevent breaking changes.
}; | ||
|
||
const MyQueryControls = () => { | ||
const [ query, setQuery ] = useState( QUERY_DEFAULTS ); | ||
const { category, categories, maxItems, minItems, numberOfItems, order, orderBy } = query; | ||
const { category, categories, maxItems, minItems, numberOfItems, order, orderBy } = query; |
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.
@Mamaduka I got confused by the use of categories
here. Technically that is also not part of the query coming from block attributes. How do you suggest we represent the orderByOptions
here, if at all?
…r sorting so we don’t attempt to resolve it
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 your review and feedback @Mamaduka! I've addressed all of your feedback. Please let me know if you have any additional questions or suggestions.
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: