Make WordPress Core

Opened 11 years ago

Last modified 6 years ago

#25493 reopened defect (bug)

Sorting posts in ascending order of date at admin side

Reported by: vinod-dalvi's profile vinod dalvi Owned by: wonderboymusic's profile wonderboymusic
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Posts, Post Types Keywords: needs-patch
Focuses: administration Cc:

Description

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 (4)

25493.patch (451 bytes) - added by vinod dalvi 11 years ago.
Patch file
25493.diff (725 bytes) - added by wonderboymusic 9 years ago.
25493.2.diff (793 bytes) - added by cklosows 9 years ago.
Uses $_GETorderby? instead of get_query_var(), like base class
25493.2.patch (2.5 KB) - added by ocean90 9 years ago.
Revert

Download all attachments as: .zip

Change History (24)

@vinod dalvi
11 years ago

Patch file

#1 @SergeyBiryukov
11 years ago

  • Version changed from 3.6.1 to 3.1

Related: [16593]

#2 @nacin
11 years ago

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

#3 @swissspidy
9 years 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
9 years ago

  • Milestone changed from Future Release to 4.4

@wonderboymusic
9 years ago

#5 @wonderboymusic
9 years 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
9 years 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
9 years 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
9 years 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
9 years ago

@wonderboymusic:

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:
https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/includes/admin/downloads/dashboard-columns.php#L115

Last edited 9 years ago by cklosows (previous) (diff)

#10 @cklosows
9 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#11 @boonebgorges
9 years ago

#34691 was marked as a duplicate.

@cklosows
9 years ago

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

#12 @cklosows
9 years ago

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

#13 @wonderboymusic
9 years 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.

This ticket was mentioned in Slack in #core by stephenharris. View the logs.


9 years ago

This ticket was mentioned in Slack in #core by ocean90. View the logs.


9 years ago

#16 @ocean90
9 years ago

  • Keywords revert added; has-patch needs-testing dev-feedback removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

@ocean90
9 years ago

Revert

#17 @ocean90
9 years ago

  • Keywords has-patch added

25493.2.patch reverts [34728] and [35482]. Part of [34728] was already reverted in [35682].

#18 @ocean90
9 years ago

In 35818:

List Tables: Revert [34728] and [35482].

Part of [34728] was already reverted in [35682], but the default values still made it impossible to set a default ordering for custom post types.

See #25493.
See #34825.

#19 @ocean90
9 years ago

In 35819:

List Tables: Revert [34728] and [35482].

Part of [34728] was already reverted in [35682], but the default values still made it impossible to set a default ordering for custom post types.

Merge of [35818] for the 4.4 branch.

See #25493.
Fixes #34825.

#20 @ocean90
9 years ago

  • Keywords needs-patch added; revert has-patch removed
  • Milestone changed from 4.4 to Future Release
Note: See TracTickets for help on using tickets.