Skip to content
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

Open
bobbingwide opened this issue Apr 30, 2021 · 5 comments
Open
Labels
[Block] Page List Affects the Page List Block [Type] Bug An existing feature does not function as intended

Comments

@bobbingwide
Copy link
Contributor

bobbingwide commented Apr 30, 2021

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 the menu_order for the sort_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.

$all_pages = get_pages(
		array(
			'sort_column' => 'menu_order, post_title, ID',
			'order'       => 'asc',
		)
	);

Step-by-step reproduction instructions

  1. Create a number of pages, some with menu order set and others not.
  2. Insert the Page List block into a page.
  3. Check the sequence is as you'd expect it.
  4. Save and view
  5. Again, check the sequence.

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.

image

With the code change shown above the Page List's sequence matches the shortcode's.

image

Code snippet (optional)

WordPress information

  • WordPress version: 5.7.1
  • Gutenberg version: 10.5.2
  • Are all plugins except Gutenberg deactivated? No.
  • Are you using a default theme (e.g. Twenty Twenty-One)? No. I'm using my thisis theme.

Device information

  • Device: Desktop
  • Operating system: Windows 10
  • Browser: Chrome Version 90.0.4430.93 (Official Build) (64-bit)
@vdwijngaert
Copy link
Member

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?

@gwwar
Copy link
Contributor

gwwar commented Apr 30, 2021

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

@bobbingwide
Copy link
Contributor Author

With the fix that I suggested, I added the Page List block to an empty menu. It looks fine to me.
image

@bobbingwide
Copy link
Contributor Author

I then added a new page called F. This magically appeared in all 3 columns. I then changed F's menu order to 999
and it moved to the bottom of the list.

@gwwar
Copy link
Contributor

gwwar commented Apr 30, 2021

@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.

@skorasaurus skorasaurus added the [Status] In Progress Tracking issues with work in progress label May 3, 2021
@skorasaurus skorasaurus added the [Block] Page List Affects the Page List Block label Dec 5, 2022
@jordesign jordesign added the [Type] Bug An existing feature does not function as intended label Sep 8, 2023
@skorasaurus skorasaurus removed the [Status] In Progress Tracking issues with work in progress label Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Page List Affects the Page List Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants