From d45a650846671a1f86fcb9c89269cb88b52038a1 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 23 Jan 2015 14:57:22 +0000 Subject: [PATCH] Introduce 'parent' parameter to `wp_get_object_terms()`. Props mikeschinkel. Fixes #15675. Built from https://develop.svn.wordpress.org/trunk@31270 git-svn-id: http://core.svn.wordpress.org/trunk@31251 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 23 +++++++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 77d53dce9e..3638f12612 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2555,6 +2555,7 @@ function wp_delete_category( $cat_ID ) { * * @since 2.3.0 * @since 4.2.0 Added support for 'taxonomy', 'parent', and 'term_taxonomy_id' values of `$orderby`. + * Introduced `$parent` parameter. * * @global wpdb $wpdb WordPress database abstraction object. * @@ -2569,6 +2570,7 @@ function wp_delete_category( $cat_ID ) { * 'all_with_object_id'. Note that 'all' or 'all_with_object_id' will result in an array of * term objects being returned, 'ids' will return an array of integers, and 'names' an array * of strings. + * @type int $parent Optional. Limit results to the direct children of a given term ID. * } * @return array|WP_Error The requested term data or empty array if no terms found. * WP_Error if any of the $taxonomies don't exist. @@ -2591,7 +2593,12 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { $object_ids = array($object_ids); $object_ids = array_map('intval', $object_ids); - $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all'); + $defaults = array( + 'orderby' => 'name', + 'order' => 'ASC', + 'fields' => 'all', + 'parent' => '', + ); $args = wp_parse_args( $args, $defaults ); $terms = array(); @@ -2652,7 +2659,19 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { } elseif ( 'all_with_object_id' == $fields ) { $select_this = 't.*, tt.*, tr.object_id'; } - $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order"; + + $where = array( + "tt.taxonomy IN ($taxonomies)", + "tr.object_id IN ($object_ids)", + ); + + if ( '' !== $args['parent'] ) { + $where[] = $wpdb->prepare( 'tt.parent = %d', $args['parent'] ); + } + + $where = implode( ' AND ', $where ); + + $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE $where $orderby $order"; $objects = false; if ( 'all' == $fields || 'all_with_object_id' == $fields ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 7085cc0cef..a2f483e7d5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31269'; +$wp_version = '4.2-alpha-31270'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.