-
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
Page List sort sequence wrong. No need to wait for core ticket 39037 #31382
Comments
I'm not sure why we would have to wait for the core ticket to be closed, like you said. The block is indeed server-side rendered. Maybe @gwwar knows why this is the case, as he appears to have written that comment? |
If folks need it sooner, it's fine to update PageList sorting first I avoided that originally, as there's an option to transform PageList to navigation links, which makes the ordering swap really obvious on the client without https://core.trac.wordpress.org/ticket/39037 being resolved |
I then added a new page called F. This magically appeared in all 3 columns. I then changed F's menu order to 999 |
@bobbingwide I dusted off #30683, if you'd like to test. We could also sort by menu order, title and ID, but existing usages in WordPress develop appear to simply use menu order and title. I don't have strong feelings on this. |
Description
The Page List block can display the site's pages in a strange order.
This is due to the fact that the request
get_pages()
is only passed themenu_order
for thesort_column
.There is a TODO item saying
When https://core.trac.wordpress.org/ticket/39037 REST API support for multiple orderby values is resolved,
update 'sort_column' to 'menu_order, post_title'. Sorting by both menu_order and post_title ensures a stable sort.
Otherwise with pages that have the same menu_order value, we can see different ordering depending on how DB
queries are constructed internally. For example we might see a different order when a limit is set to <499
versus >= 500.
I can't see why we need to wait for the REST API to catch up since in the editor the block is server side rendered.
If we change the code to include the additional columns to make the ordering unique then what we see in the editor and the front end will be consistent.
Step-by-step reproduction instructions
Expected behaviour
My expectation is that the pages in each level of the tree should be ordered by menu_order, then by page title, then ID.
If there are two or more titles with the same menu order then the post ID would be used make the compound key unique.
Actual behaviour
Pages without menu_order set are randomly ordered.
Screenshots or screen recording (optional)
The first screenshot shows the Page List in the middle.
To the left is a table showing the top level pages correctly ordered by menu_order, title and ID
To the right is the output of a
[bw_tree]
shortcode, with the sort order set to the same: menu_order, title and ID.With the code change shown above the Page List's sequence matches the shortcode's.
Code snippet (optional)
WordPress information
thisis
theme.Device information
The text was updated successfully, but these errors were encountered: