Make WordPress Core

Opened 2 years ago

Closed 13 days ago

#25493 closed defect (bug) (fixed)

Sorting posts in ascending order of date at admin side

Reported by: vinod dalvi Owned by: wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.1
Component: Posts, Post Types Keywords: has-patch needs-testing dev-feedback
Focuses: administration Cc:


Posts are displayed in descending order of date in the admin side but if we click on date column header to sort it then again it is sorted in descending order of date instead it should be sorted in ascending order of date.

Attachments (3)

25493.patch (451 bytes) - added by vinod dalvi 2 years ago.
Patch file
25493.diff (725 bytes) - added by wonderboymusic 3 months ago.
25493.2.diff (793 bytes) - added by cklosows 2 weeks ago.
Uses $_GETorderby? instead of get_query_var(), like base class

Download all attachments as: .zip

Change History (16)

@vinod dalvi
2 years ago

Patch file

#1 @SergeyBiryukov
2 years ago

  • Version changed from 3.6.1 to 3.1

Related: [16593]

#2 @nacin
22 months ago

  • Component changed from Administration to Posts, Post Types
  • Focuses administration added

#3 @swissspidy
3 months ago

  • Keywords commit added; 2nd-opinion needs-testing removed
  • Milestone changed from Awaiting Review to Future Release

Patch still applies and works like a charm:

  1. Posts are still sorted in descending order by default.
  2. Clicking the column changes order to ascending (instead of still being in descending order).

Sounds like a no-brainer to me.

#4 @swissspidy
3 months ago

  • Milestone changed from Future Release to 4.4

#5 @wonderboymusic
3 months ago

  • Keywords commit removed

Probably needs to be more like 25493.diff, which is still weird - it's not the right solution because it arbitrarily defaults to date. In the previous patch, the CSS classes weren't reflecting the proper state. There is no real holder of the state of the request, so it is hard to parse out what the values of orderby and order are when there is no query string. order gets filled in, orderby does not.

#6 @swissspidy
3 months ago

  • Keywords needs-refresh added

Hmm this also breaks the page list table, as you can see here: https://cloudup.com/cpFvtS3S_7p

It indicates that pages are ordered by date, but in fact they're ordered alphabetically.

#7 @wonderboymusic
2 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34728:

Post List Table: Ensure that edit.php with no query string produces the proper markup and links in the date column header.

Add 2 methods to WP_List_Table, ->get_orderby() and ->get_order(). Override the methods in WP_Posts_List_Table.

WP_Posts_List_Table calls wp_edit_posts_query() in ->prepare_items() which is a wrapper for wp(). As such, we can obtain orderby and order via get_query_var(), instead of the URL.

Fixes #25493.

#8 @SergeyBiryukov
4 weeks ago

In 35482:

Post List Table: Hierarchical post types should not default to sorting by date.

Regression introduced in [34728].

Props ellie.roepken.
Fixes #34473. See #25493.

#9 @cklosows
3 weeks ago


The addition of the get_orderby and get_order methods in class-wp-posts-list-table.php seems to have caused the sorting of custom columns for a custom post type fail when using the filter method, instead of extending the WP_List_Table class.

In the main class-wp-list-table.php these methods pull from $_GET

	 * If 'orderby' is set, return it.
	 * @access protected
	 * @since 4.4.0
	 * @return string The value of 'orderby' or empty string.
	protected function get_orderby() {
		if ( isset( $_GET['orderby'] ) ) {
			return $_GET['orderby'];

		return '';

	 * If 'order' is 'desc', return it. Else return 'asc'.
	 * @access protected
	 * @since 4.4.0
	 * @return string 'desc' or 'asc'.
	protected function get_order() {
		if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
			return 'desc';

		return 'asc';

However in class-wp-posts-list-table.php they are relying on the get_query_var() function, which in order to do a meta query sort, requires setting the orderby to meta_value or meta_value_num.

Am I missing something in this case? Here is a link to the implementation used in the Easy Digital Downloads core:

Last edited 3 weeks ago by cklosows (previous) (diff)

#10 @cklosows
3 weeks ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#11 @boonebgorges
2 weeks ago

#34691 was marked as a duplicate.

2 weeks ago

Uses $_GETorderby? instead of get_query_var(), like base class

#12 @cklosows
2 weeks ago

  • Keywords needs-testing dev-feedback added; needs-refresh removed

#13 @wonderboymusic
13 days ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 35682:

List Tables: After [34728], don't try to infer orderby from query params.

List tables are really good.

Props cklosows.
Fixes #25493.

Note: See TracTickets for help on using tickets.