<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[38667] trunk: Taxonomy: Use `WP_Term_Query` when querying for object terms.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/38667">38667</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/38667","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-09-28 03:54:36 +0000 (Wed, 28 Sep 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Taxonomy: Use `WP_Term_Query` when querying for object terms.
The new 'object_ids' parameter for `WP_Term_Query` allows queries for
terms that "belong to" a given object. This change makes it possible
to use `WP_Term_Query` inside of `wp_get_object_terms()`, rather than
assembling a SQL query.
The refactor has a couple of benefits:
* Less redundancy.
* Better consistency in accepted arguments between the term query functions. See <a href="https://core.trac.wordpress.org/ticket/31105">#31105</a>.
* Less redundancy.
* Object term queries are now cached. The `get_object_term_cache()` cache remains, and will be a somewhat less fragile secondary cache in front of the query cache (which is subject to frequent invalidation).
* Less redundancy.
A small breaking change: Previously, if a non-hierarchical taxonomy had
terms that had a non-zero 'parent' (perhaps because of a direct SQL
query), `wp_get_object_terms()` would respect the 'parent' argument.
This is in contrast to `WP_Term_Query` and `get_terms()`, which have
always rejected 'parent' queries for non-hierarchical taxonomies. For
consistency, the behavior of `get_terms()` is being applied across the
board: passing 'parent' for a non-hierarchical taxonomy will result in
an empty result set (since the cached taxonomy hierarchy will be empty).
Props flixos90, boonebgorges.
See <a href="https://core.trac.wordpress.org/ticket/37198">#37198</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswptermqueryphp">trunk/src/wp-includes/class-wp-term-query.php</a></li>
<li><a href="#trunksrcwpincludestaxonomyphp">trunk/src/wp-includes/taxonomy.php</a></li>
<li><a href="#trunktestsphpunitteststermqueryphp">trunk/tests/phpunit/tests/term/query.php</a></li>
<li><a href="#trunktestsphpunitteststermwpGetObjectTermsphp">trunk/tests/phpunit/tests/term/wpGetObjectTerms.php</a></li>
<li><a href="#trunktestsphpunitteststermwpSetObjectTermsphp">trunk/tests/phpunit/tests/term/wpSetObjectTerms.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswptermqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-term-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-term-query.php 2016-09-28 00:16:44 UTC (rev 38666)
+++ trunk/src/wp-includes/class-wp-term-query.php 2016-09-28 03:54:36 UTC (rev 38667)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -100,6 +100,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.6.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.6.0 Introduced 'term_taxonomy_id' parameter.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 Introduced 'object_ids' parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|array $query {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -107,6 +108,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string|array $taxonomy Taxonomy name, or array of taxonomies, to which results should
</span><span class="cx" style="display: block; padding: 0 10px"> * be limited.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type int|array $object_ids Optional. Object ID, or array of object IDs. Results will be
+ * limited to terms associated with these objects.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type string $orderby Field(s) to order terms by. Accepts term fields ('name',
</span><span class="cx" style="display: block; padding: 0 10px"> * 'slug', 'term_group', 'term_id', 'id', 'description'),
</span><span class="cx" style="display: block; padding: 0 10px"> * 'count' for term taxonomy count, 'include' to match the
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -130,13 +133,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * positive number. Default ''|0 (all).
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $offset The number by which to offset the terms query. Default empty.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $fields Term fields to query for. Accepts 'all' (returns an array of
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * complete term objects), 'ids' (returns an array of ids),
- * 'id=>parent' (returns an associative array with ids as keys,
- * parent term IDs as values), 'names' (returns an array of term
- * names), 'count' (returns the number of matching terms),
- * 'id=>name' (returns an associative array with ids as keys,
- * term names as values), or 'id=>slug' (returns an associative
- * array with ids as keys, term slugs as values). Default 'all'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * complete term objects), 'all_with_object_id' (returns an
+ * array of term objects with the 'object_id' param; only works
+ * when the `$fields` parameter is 'object_ids' ), 'ids'
+ * (returns an array of ids), 'tt_ids' (returns an array of
+ * term taxonomy ids), 'id=>parent' (returns an associative
+ * array with ids as keys, parent term IDs as values), 'names'
+ * (returns an array of term names), 'count' (returns the number
+ * of matching terms), 'id=>name' (returns an associative array
+ * with ids as keys, term names as values), or 'id=>slug'
+ * (returns an associative array with ids as keys, term slugs
+ * as values). Default 'all'.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type bool $count Whether to return a term count (true) or array of term objects
</span><span class="cx" style="display: block; padding: 0 10px"> * (false). Will take precedence over `$fields` if true.
</span><span class="cx" style="display: block; padding: 0 10px"> * Default false.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -183,6 +190,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->query_var_defaults = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'taxonomy' => null,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'object_ids' => null,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'orderby' => 'name',
</span><span class="cx" style="display: block; padding: 0 10px"> 'order' => 'ASC',
</span><span class="cx" style="display: block; padding: 0 10px"> 'hide_empty' => true,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -392,7 +400,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $orderby = $this->parse_orderby( $this->query_vars['orderby'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 'term_order' is a legal sort order only when joining the relationship table.
+ $_orderby = $this->query_vars['orderby'];
+ if ( 'term_order' === $_orderby && empty( $this->query_vars['object_ids'] ) ) {
+ $_orderby = 'term_id';
+ }
+ $orderby = $this->parse_orderby( $_orderby );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $orderby ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $orderby = "ORDER BY $orderby";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -507,6 +521,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['where']['description__like'] = $this->db->prepare( "tt.description LIKE %s", '%' . $this->db->esc_like( $args['description__like'] ) . '%' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $args['object_ids'] ) ) {
+ $object_ids = $args['object_ids'];
+ if ( ! is_array( $object_ids ) ) {
+ $object_ids = array( $object_ids );
+ }
+
+ $object_ids = implode( ', ', array_map( 'intval', $object_ids ) );
+ $this->sql_clauses['where']['object_ids'] = "tr.object_id IN ($object_ids)";
+ }
+
+ /*
+ * When querying for object relationships, the 'count > 0' check
+ * added by 'hide_empty' is superfluous.
+ */
+ if ( ! empty( $args['object_ids'] ) ) {
+ $args['hide_empty'] = false;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( '' !== $parent ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $parent = (int) $parent;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['where']['parent'] = "tt.parent = '$parent'";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -558,7 +590,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $selects = array();
</span><span class="cx" style="display: block; padding: 0 10px"> switch ( $args['fields'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'all':
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'all_with_object_id' :
+ case 'tt_ids' :
+ case 'slugs' :
</ins><span class="cx" style="display: block; padding: 0 10px"> $selects = array( 't.*', 'tt.*' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'all_with_object_id' === $args['fields'] && ! empty( $args['object_ids'] ) ) {
+ $selects[] = 'tr.object_id';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'ids':
</span><span class="cx" style="display: block; padding: 0 10px"> case 'id=>parent':
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -602,6 +640,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $join .= " INNER JOIN {$this->db->term_taxonomy} AS tt ON t.term_id = tt.term_id";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $this->query_vars['object_ids'] ) ) {
+ $join .= " INNER JOIN {$this->db->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id";
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $where = implode( ' AND ', $this->sql_clauses['where'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -657,7 +699,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $terms = $this->db->get_results( $this->request );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'all' == $_fields ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> update_term_cache( $terms );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -708,6 +750,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * When querying for terms connected to objects, we may get
+ * duplicate results. The duplicates should be preserved if
+ * `$fields` is 'all_with_object_id', but should otherwise be
+ * removed.
+ */
+ if ( ! empty( $args['object_ids'] ) && 'all_with_object_id' != $_fields ) {
+ $_tt_ids = $_terms = array();
+ foreach ( $terms as $term ) {
+ if ( isset( $_tt_ids[ $term->term_id ] ) ) {
+ continue;
+ }
+
+ $_tt_ids[ $term->term_id ] = 1;
+ $_terms[] = $term;
+ }
+
+ $terms = $_terms;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $_terms = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'id=>parent' == $_fields ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $terms as $term ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -715,12 +777,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( 'ids' == $_fields ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $terms as $term ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_terms[] = $term->term_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_terms[] = (int) $term->term_id;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( 'tt_ids' == $_fields ) {
+ foreach ( $terms as $term ) {
+ $_terms[] = (int) $term->term_taxonomy_id;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> } elseif ( 'names' == $_fields ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $terms as $term ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $_terms[] = $term->name;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( 'slugs' == $_fields ) {
+ foreach ( $terms as $term ) {
+ $_terms[] = $term->slug;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> } elseif ( 'id=>name' == $_fields ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $terms as $term ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $_terms[ $term->term_id ] = $term->name;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -746,7 +816,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'all' === $_fields ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $terms = array_map( 'get_term', $terms );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -766,19 +836,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected function parse_orderby( $orderby_raw ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $_orderby = strtolower( $orderby_raw );
</span><span class="cx" style="display: block; padding: 0 10px"> $maybe_orderby_meta = false;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'count' == $_orderby ) {
- $orderby = 'tt.count';
- } elseif ( 'name' == $_orderby ) {
- $orderby = 't.name';
- } elseif ( 'slug' == $_orderby ) {
- $orderby = 't.slug';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( in_array( $_orderby, array( 'term_id', 'name', 'slug', 'term_group' ), true ) ) {
+ $orderby = "t.$_orderby";
+ } elseif ( in_array( $_orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id', 'description' ), true ) ) {
+ $orderby = "tt.$_orderby";
+ } elseif ( 'term_order' === $_orderby ) {
+ $orderby = 'tr.term_order';
</ins><span class="cx" style="display: block; padding: 0 10px"> } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $orderby = "FIELD( t.term_id, $include )";
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( 'term_group' == $_orderby ) {
- $orderby = 't.term_group';
- } elseif ( 'description' == $_orderby ) {
- $orderby = 'tt.description';
</del><span class="cx" style="display: block; padding: 0 10px"> } elseif ( 'none' == $_orderby ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $orderby = '';
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) {
</span></span></pre></div>
<a id="trunksrcwpincludestaxonomyphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/taxonomy.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/taxonomy.php 2016-09-28 00:16:44 UTC (rev 38666)
+++ trunk/src/wp-includes/taxonomy.php 2016-09-28 03:54:36 UTC (rev 38667)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1941,27 +1941,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Introduced `$parent` argument.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.4.0 Introduced `$meta_query` and `$update_term_meta_cache` arguments. When `$fields` is 'all' or
</span><span class="cx" style="display: block; padding: 0 10px"> * 'all_with_object_id', an array of `WP_Term` objects will be returned.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0 Refactored to use WP_Term_Query, and to support any WP_Term_Query arguments.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global wpdb $wpdb WordPress database abstraction object.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int|array $object_ids The ID(s) of the object(s) to retrieve.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|array $taxonomies The taxonomies to retrieve terms from.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array|string $args {
- * Array of arguments.
- * @type string $orderby Field by which results should be sorted. Accepts 'name', 'count', 'slug',
- * 'term_group', '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 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.
- * @type bool $update_term_meta_cache Whether to prime termmeta cache for matched terms. Only applies when
- * `$fields` is 'all', 'all_with_object_id', or 'term_id'. Default true.
- * @type array $meta_query Meta query clauses to limit retrieved terms by. See `WP_Meta_Query`.
- * Default empty.
- * }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array|string $args See WP_Term_Query::__construct() for supported arguments.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array|WP_Error The requested term data or empty array if no terms found.
</span><span class="cx" style="display: block; padding: 0 10px"> * WP_Error if any of the $taxonomies don't exist.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1983,186 +1969,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $object_ids = array($object_ids);
</span><span class="cx" style="display: block; padding: 0 10px"> $object_ids = array_map('intval', $object_ids);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $defaults = array(
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'fields' => 'all',
- 'parent' => '',
- 'update_term_meta_cache' => true,
- 'meta_query' => '',
- );
- $args = wp_parse_args( $args, $defaults );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $args['taxonomy'] = $taxonomies;
+ $args['object_ids'] = $object_ids;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $terms = array();
- if ( count($taxonomies) > 1 ) {
- foreach ( $taxonomies as $index => $taxonomy ) {
- $t = get_taxonomy($taxonomy);
- if ( isset($t->args) && is_array($t->args) && $args != array_merge($args, $t->args) ) {
- unset($taxonomies[$index]);
- $terms = array_merge($terms, wp_get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args)));
- }
- }
- } else {
- $t = get_taxonomy($taxonomies[0]);
- if ( isset($t->args) && is_array($t->args) )
- $args = array_merge($args, $t->args);
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $terms = get_terms( $args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $orderby = $args['orderby'];
- $order = $args['order'];
- $fields = $args['fields'];
-
- if ( in_array( $orderby, array( 'term_id', 'name', 'slug', 'term_group' ) ) ) {
- $orderby = "t.$orderby";
- } elseif ( in_array( $orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id' ) ) ) {
- $orderby = "tt.$orderby";
- } elseif ( 'term_order' === $orderby ) {
- $orderby = 'tr.term_order';
- } elseif ( 'none' === $orderby ) {
- $orderby = '';
- $order = '';
- } else {
- $orderby = 't.term_id';
- }
-
- // tt_ids queries can only be none or tr.term_taxonomy_id
- if ( ('tt_ids' == $fields) && !empty($orderby) )
- $orderby = 'tr.term_taxonomy_id';
-
- if ( !empty($orderby) )
- $orderby = "ORDER BY $orderby";
-
- $order = strtoupper( $order );
- if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) )
- $order = 'ASC';
-
- $taxonomy_array = $taxonomies;
- $object_id_array = $object_ids;
- $taxonomies = "'" . implode("', '", array_map( 'esc_sql', $taxonomies ) ) . "'";
- $object_ids = implode(', ', $object_ids);
-
- $select_this = '';
- if ( 'all' == $fields ) {
- $select_this = 't.*, tt.*';
- } elseif ( 'ids' == $fields ) {
- $select_this = 't.term_id';
- } elseif ( 'names' == $fields ) {
- $select_this = 't.name';
- } elseif ( 'slugs' == $fields ) {
- $select_this = 't.slug';
- } elseif ( 'all_with_object_id' == $fields ) {
- $select_this = 't.*, tt.*, tr.object_id';
- }
-
- $where = array(
- "tt.taxonomy IN ($taxonomies)",
- "tr.object_id IN ($object_ids)",
- );
-
- if ( '' !== $args['parent'] ) {
- $where[] = $wpdb->prepare( 'tt.parent = %d', $args['parent'] );
- }
-
- // Meta query support.
- $meta_query_join = '';
- if ( ! empty( $args['meta_query'] ) ) {
- $mquery = new WP_Meta_Query( $args['meta_query'] );
- $mq_sql = $mquery->get_sql( 'term', 't', 'term_id' );
-
- $meta_query_join .= $mq_sql['join'];
-
- // Strip leading AND.
- $where[] = preg_replace( '/^\s*AND/', '', $mq_sql['where'] );
- }
-
- $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 $meta_query_join WHERE $where $orderby $order";
-
- $objects = false;
- if ( 'all' == $fields || 'all_with_object_id' == $fields ) {
- $_terms = $wpdb->get_results( $query );
- $object_id_index = array();
- foreach ( $_terms as $key => $term ) {
- $term = sanitize_term( $term, $taxonomy, 'raw' );
- $_terms[ $key ] = $term;
-
- if ( isset( $term->object_id ) ) {
- $object_id_index[ $key ] = $term->object_id;
- }
- }
-
- update_term_cache( $_terms );
- $_terms = array_map( 'get_term', $_terms );
-
- // Re-add the object_id data, which is lost when fetching terms from cache.
- if ( 'all_with_object_id' === $fields ) {
- foreach ( $_terms as $key => $_term ) {
- if ( isset( $object_id_index[ $key ] ) ) {
- $_term->object_id = $object_id_index[ $key ];
- }
- }
- }
-
- $terms = array_merge( $terms, $_terms );
- $objects = true;
-
- } elseif ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) {
- $_terms = $wpdb->get_col( $query );
- $_field = ( 'ids' == $fields ) ? 'term_id' : 'name';
- foreach ( $_terms as $key => $term ) {
- $_terms[$key] = sanitize_term_field( $_field, $term, $term, $taxonomy, 'raw' );
- }
- $terms = array_merge( $terms, $_terms );
- } elseif ( 'tt_ids' == $fields ) {
- $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order");
- foreach ( $terms as $key => $tt_id ) {
- $terms[$key] = sanitize_term_field( 'term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw' ); // 0 should be the term id, however is not needed when using raw context.
- }
- }
-
- // Update termmeta cache, if necessary.
- if ( $args['update_term_meta_cache'] && ( 'all' === $fields || 'all_with_object_id' === $fields || 'ids' === $fields ) ) {
- if ( 'ids' === $fields ) {
- $term_ids = $terms;
- } else {
- $term_ids = wp_list_pluck( $terms, 'term_id' );
- }
-
- update_termmeta_cache( $term_ids );
- }
-
- if ( ! $terms ) {
- $terms = array();
- } elseif ( $objects && 'all_with_object_id' !== $fields ) {
- $_tt_ids = array();
- $_terms = array();
- foreach ( $terms as $term ) {
- if ( in_array( $term->term_taxonomy_id, $_tt_ids ) ) {
- continue;
- }
-
- $_tt_ids[] = $term->term_taxonomy_id;
- $_terms[] = $term;
- }
- $terms = $_terms;
- } elseif ( ! $objects ) {
- $terms = array_values( array_unique( $terms ) );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the terms for a given object or objects.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $terms An array of terms for the given object or objects.
- * @param array $object_id_array Array of object IDs for which `$terms` were retrieved.
- * @param array $taxonomy_array Array of taxonomies from which `$terms` were retrieved.
- * @param array $args An array of arguments for retrieving terms for the given
- * object(s). See wp_get_object_terms() for details.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $terms An array of terms for the given object or objects.
+ * @param array $object_ids Array of object IDs for which `$terms` were retrieved.
+ * @param array $taxonomies Array of taxonomies from which `$terms` were retrieved.
+ * @param array $args An array of arguments for retrieving terms for the given
+ * object(s). See wp_get_object_terms() for details.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $terms = apply_filters( 'get_object_terms', $terms, $object_id_array, $taxonomy_array, $args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $terms = apply_filters( 'get_object_terms', $terms, $object_ids, $taxonomies, $args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $object_ids = implode( ',', $object_ids );
+ $taxonomies = implode( ',', $taxonomies );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the terms for a given object or objects.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunktestsphpunitteststermqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/term/query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/term/query.php 2016-09-28 00:16:44 UTC (rev 38666)
+++ trunk/tests/phpunit/tests/term/query.php 2016-09-28 03:54:36 UTC (rev 38667)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -144,6 +144,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 37198
+ */
+ public function test_order_by_term_order_should_fall_back_on_term_id_when_relationship_table_is_not_being_joined() {
+ register_taxonomy( 'wptests_tax', 'post' );
+ $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
+ sort( $terms );
+
+ $q = new WP_Term_Query( array(
+ 'taxonomy' => 'wptests_tax',
+ 'orderby' => 'term_order',
+ 'fields' => 'ids',
+ 'hide_empty' => false,
+ ) );
+
+ $this->assertSame( $terms, $q->get_terms() );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 37591
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_terms_is_set() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -185,4 +203,123 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( array( $t1, $t2 ), $terms );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 37198
+ */
+ public function test_object_ids_single() {
+ register_taxonomy( 'wptests_tax_1', 'post' );
+
+ $p = self::factory()->post->create();
+ $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
+
+ wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' );
+
+ $query = new WP_Term_Query( array(
+ 'taxonomy' => 'wptests_tax_1',
+ 'object_ids' => $p,
+ 'fields' => 'ids',
+ ) );
+
+ $this->assertEqualSets( array( $t ), $query->terms );
+ }
+
+ /**
+ * @ticket 37198
+ */
+ public function test_object_ids_array() {
+ register_taxonomy( 'wptests_tax_1', 'post' );
+
+ $p = self::factory()->post->create();
+ $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
+
+ wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' );
+
+ $query = new WP_Term_Query( array(
+ 'taxonomy' => 'wptests_tax_1',
+ 'object_ids' => array( $p ),
+ 'fields' => 'ids',
+ ) );
+
+ $this->assertEqualSets( array( $t ), $query->terms );
+ }
+
+ /**
+ * @ticket 37198
+ */
+ public function test_duplicates_should_be_removed_for_fields_all() {
+ register_taxonomy( 'wptests_tax_1', 'post' );
+ $posts = self::factory()->post->create_many( 2 );
+ $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
+
+ foreach ( $posts as $p ) {
+ wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' );
+ }
+
+ $query = new WP_Term_Query( array(
+ 'taxonomy' => 'wptests_tax_1',
+ 'object_ids' => $posts,
+ 'fields' => 'all',
+ ) );
+
+ $this->assertSame( 1, count( $query->terms ) );
+ $this->assertSame( $t, reset( $query->terms )->term_id );
+ }
+
+ /**
+ * @ticket 37198
+ */
+ public function test_duplicates_should_not_be_removed_for_fields_all_with_object_id() {
+ register_taxonomy( 'wptests_tax_1', 'post' );
+ $posts = self::factory()->post->create_many( 2 );
+ $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
+
+ foreach ( $posts as $p ) {
+ wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' );
+ }
+
+ $query = new WP_Term_Query( array(
+ 'taxonomy' => 'wptests_tax_1',
+ 'object_ids' => $posts,
+ 'fields' => 'all_with_object_id',
+ ) );
+
+ $this->assertSame( 2, count( $query->terms ) );
+ foreach ( $query->terms as $term ) {
+ $this->assertSame( $t, $term->term_id );
+ }
+ }
+
+ /**
+ * @ticket 37198
+ * @group cache
+ */
+ public function test_object_ids_cache_should_be_invalidated_by_term_relationship_change() {
+ register_taxonomy( 'wptests_tax_1', 'post' );
+
+ $p = self::factory()->post->create();
+ $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) );
+
+ wp_set_object_terms( $p, array( $terms[0] ), 'wptests_tax_1' );
+
+ $query = new WP_Term_Query( array(
+ 'taxonomy' => 'wptests_tax_1',
+ 'object_ids' => $p,
+ 'fields' => 'ids',
+ ) );
+ $found = $query->get_terms();
+
+ $this->assertEqualSets( array( $terms[0] ), $found );
+
+ wp_set_object_terms( $p, array( $terms[1] ), 'wptests_tax_1' );
+
+ $query = new WP_Term_Query( array(
+ 'taxonomy' => 'wptests_tax_1',
+ 'object_ids' => $p,
+ 'fields' => 'ids',
+ ) );
+ $found = $query->get_terms();
+
+ $this->assertEqualSets( array( $terms[1] ), $found );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitteststermwpGetObjectTermsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/term/wpGetObjectTerms.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/term/wpGetObjectTerms.php 2016-09-28 00:16:44 UTC (rev 38666)
+++ trunk/tests/phpunit/tests/term/wpGetObjectTerms.php 2016-09-28 03:54:36 UTC (rev 38667)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -23,7 +23,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 3, count($tt_1) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // make sure they're correct
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'slugs', 'orderby' => 't.term_id'));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'slugs', 'orderby' => 'term_id'));
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $terms_1_slugs, $terms );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -360,26 +360,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 15675
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_parent() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_taxonomy( 'wptests_tax2', 'post', array(
+ 'hierarchical' => true,
+ ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $t1 = self::factory()->term->create( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'taxonomy' => $this->taxonomy,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'taxonomy' => 'wptests_tax2',
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $t2 = self::factory()->term->create( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'taxonomy' => $this->taxonomy,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'taxonomy' => 'wptests_tax2',
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $t3 = self::factory()->term->create( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'taxonomy' => $this->taxonomy,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'taxonomy' => 'wptests_tax2',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'parent' => $t1,
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $t4 = self::factory()->term->create( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'taxonomy' => $this->taxonomy,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'taxonomy' => 'wptests_tax2',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'parent' => $t2,
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $p = self::factory()->post->create();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_set_object_terms( $p, array( $t1, $t2, $t3, $t3 ), $this->taxonomy );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_object_terms( $p, array( $t1, $t2, $t3, $t3 ), 'wptests_tax2' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $found = wp_get_object_terms( $p, $this->taxonomy, array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $found = wp_get_object_terms( $p, 'wptests_tax2', array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'parent' => $t1,
</span><span class="cx" style="display: block; padding: 0 10px"> 'fields' => 'ids',
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span></span></pre></div>
<a id="trunktestsphpunitteststermwpSetObjectTermsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/term/wpSetObjectTerms.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/term/wpSetObjectTerms.php 2016-09-28 00:16:44 UTC (rev 38666)
+++ trunk/tests/phpunit/tests/term/wpSetObjectTerms.php 2016-09-28 03:54:36 UTC (rev 38667)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -259,7 +259,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 3, count($tt_1) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // make sure they're correct
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id'));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 'term_id'));
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $terms_1, $terms );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // change the terms
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -267,7 +267,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 2, count($tt_2) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // make sure they're correct
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id'));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 'term_id'));
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $terms_2, $terms );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // make sure the tt id for 'bar' matches
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -288,7 +288,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 3, count($tt_1) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // make sure they're correct
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id'));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 'term_id'));
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $terms_1, $terms );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // change the terms
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -296,7 +296,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 2, count($tt_2) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // make sure they're correct
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id'));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 'term_id'));
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $terms_2, $terms );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // make sure the tt id for 'bar' matches
</span></span></pre>
</div>
</div>
</body>
</html>