From 2cdc8ec43a1782f2e2ea930b79abb4804897f0b6 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 5 Sep 2023 20:48:24 +0000 Subject: [PATCH] Posts, Post Types: Reinstate missing sort_column options in get_pages(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes an issue introduced in [55569] that broke sort ordering by `post_modified_gmt` or `modified_gmt`. Props david.binda, azaozz, spacedmonkey, flixos90, joemcgill. Merges [56490] to the 6.3 branch. Fixes #59226. Built from https://develop.svn.wordpress.org/branches/6.3@56517 git-svn-id: http://core.svn.wordpress.org/branches/6.3@56029 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 16 +++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index f26e0b634c..59745dbf75 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -6066,8 +6066,22 @@ function get_pages( $args = array() ) { $query_args['post_parent'] = $parent; } + /* + * Maintain backward compatibility for `sort_column` key. + * Additionally to `WP_Query`, it has been supporting the `post_modified_gmt` field, so this logic will translate + * it to `post_modified` which should result in the same order given the two dates in the fields match. + */ $orderby = wp_parse_list( $parsed_args['sort_column'] ); - $orderby = array_map( 'trim', $orderby ); + $orderby = array_map( + static function( $orderby_field ) { + $orderby_field = trim( $orderby_field ); + if ( 'post_modified_gmt' === $orderby_field || 'modified_gmt' === $orderby_field ) { + $orderby_field = str_replace( '_gmt', '', $orderby_field ); + } + return $orderby_field; + }, + $orderby + ); if ( $orderby ) { $query_args['orderby'] = array_fill_keys( $orderby, $parsed_args['sort_order'] ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 26dbb6d700..1f46f9e638 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3.2-alpha-56516'; +$wp_version = '6.3.2-alpha-56517'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.