Make WordPress Core

Opened 20 months ago

Last modified 12 months ago

#38238 reviewing enhancement

Sorting a list table by some kind of count should default to DESC initially

Reported by: helen Owned by: helen
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: good-first-bug has-patch needs-testing
Focuses: Cc:


List tables that can be sorted by some kind of count (posts with that term, comments on that post, etc.) should likely use DESC for that sort initially, as more frequent user workflows involve wanting to see things with many X (popularity/usage), as opposed to items with no X (cleanup). For example, you may want to see which categories are most popular (related: #36964) or which posts have generated a lot of comments.

Should also consider how sortable custom columns indicate whether to use ASC or DESC initially.

Attachments (4)

38238.diff (2.1 KB) - added by terwdan 20 months ago.
38238.2.diff (4.2 KB) - added by Harold Angenent 20 months ago.
38238.3.diff (4.6 KB) - added by drebbits.web 20 months ago.
Only added submitted date sort in the comments table
38238.4.diff (11.0 KB) - added by rcutmore 12 months ago.
Add tests and update code formatting (based on 38238.2.diff)

Download all attachments as: .zip

Change History (12)

#1 @afercia
20 months ago

Related: #32170

... review the ordering associated with the "first click" on a header link. For example, in the Posts table clicking the Comments header the first time gives an ascending order by Comments count, showing the Posts with 0 comments first, while probably would be more useful to have the Posts with the higher number of Comments displayed first.

#2 @helen
20 months ago

  • Keywords good-first-bug added

20 months ago

#3 @terwdan
20 months ago

  • Keywords has-patch needs-testing needs-unit-tests added; needs-patch removed

I've attached a patch I made on WCNL2016. This should hopefully fix the issue by switching the ascending and descending on the column sort.

#4 @Harold Angenent
20 months ago

Attached a patch also created on WCNL, which holds a different approach.

This patch introduces a new way to communicate with the manage_{$this->screen->id}_sortable_columns filter, which uses an associative array instead of an indexed array to make each property more clear. Usage:

$sortable['column_name'] = array(
    'query_var' => 'query_var_name',
    'order'     => 'DESC',

The patch also switches around the default sorting behaviour (to DESC) for:

  • WP_Links_List_Table: rating
  • WP_Media_List_Table: comment_count
  • WP_MS_Users_List_Table: registered date
  • WP_Posts_List_Table: comment_count (as proposed in the ticket description)
  • WP_Terms_List_Table: posts count (as proposed in the ticket description)

#5 @drebbits.web
20 months ago

@harold-angenent 's approach seems to be the appropriate & flexible solution and developers can easily add the 'order' argument when adding their own custom column that has some sort of count quality.

20 months ago

Only added submitted date sort in the comments table

#6 @Harold Angenent
20 months ago

@drebbits.web Thanks for your feedback and help! I consciously chose to not make the date in the comments table descending by default, because of the comments of @afercia on #32416. Since comments are already displayed 'last comment first' by default, clicking "date" for the first time should probably change this around.

#7 @johnbillion
19 months ago

  • Owner set to helen
  • Status changed from new to reviewing

12 months ago

Add tests and update code formatting (based on 38238.2.diff)

#8 @rcutmore
12 months ago

  • Keywords needs-unit-tests removed

I added 38238.4.diff, which is based on 38238.2.diff due to the previous comment about the date column in the comments table). This updates the code formatting to more closely follow the project coding guidelines and adds tests to check the default sorting in the various tables.

Note: See TracTickets for help on using tickets.