From 42ec13030cfad00003dcdd8790884beab9b3866e Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sun, 18 Jan 2015 18:57:23 +0000 Subject: [PATCH] Additional 'orderby' values for `wp_get_object_terms()`. Adds support for ordering by 'taxonomy', 'term_taxonomy_id', and 'parent'. Props ChriCo. Fixes #28688. Built from https://develop.svn.wordpress.org/trunk@31236 git-svn-id: http://core.svn.wordpress.org/trunk@31217 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 18 +++++++----------- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index ba70344253..9506a347db 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2562,7 +2562,7 @@ function wp_delete_category( $cat_ID ) { * @param array|string $args { * Array of arguments. * @type string $orderby Field by which results should be sorted. Accepts 'name', 'count', 'slug', 'term_group', - * or 'term_order'. Default 'name'. + * 'term_order', 'taxonomy', 'parent', or 'term_taxonomy_id'. Default 'name'. * @type string $order Sort order. Accepts 'ASC' or 'DESC'. Default 'ASC'. * @type string $fields Fields to return for matched terms. Accepts 'all', 'ids', 'names', and * 'all_with_object_id'. Note that 'all' or 'all_with_object_id' will result in an array of @@ -2612,17 +2612,13 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { $order = $args['order']; $fields = $args['fields']; - if ( 'count' == $orderby ) { - $orderby = 'tt.count'; - } elseif ( 'name' == $orderby ) { - $orderby = 't.name'; - } elseif ( 'slug' == $orderby ) { - $orderby = 't.slug'; - } elseif ( 'term_group' == $orderby ) { - $orderby = 't.term_group'; - } elseif ( 'term_order' == $orderby ) { + if ( in_array( $orderby, array( 'term_id', 'name', 'slug', 'term_group' ) ) ) { + $orderby = "t.$orderby"; + } else if ( in_array( $orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id' ) ) ) { + $orderby = "tt.$orderby"; + } else if ( 'term_order' === $orderby ) { $orderby = 'tr.term_order'; - } elseif ( 'none' == $orderby ) { + } else if ( 'none' === $orderby ) { $orderby = ''; $order = ''; } else { diff --git a/wp-includes/version.php b/wp-includes/version.php index d8fc662214..9324dad129 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31235'; +$wp_version = '4.2-alpha-31236'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.