Taxononmy: Set WP_Term_Query::terms when returning terms from the cache in WP_Term_Query::get_terms().

Merge of [38211] and [38212] to the 4.6 branch.

Props wonderboymusic.
Props boonebgorges for review.
Fixes #37591.

git-svn-id: https://develop.svn.wordpress.org/branches/4.6@38214 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling 2016-08-08 13:13:56 +00:00
parent 692c93bc39
commit d3f17e6dbc
2 changed files with 25 additions and 1 deletions

View File

@ -641,7 +641,8 @@ class WP_Term_Query {
$cache = array_map( 'get_term', $cache );
}
return $cache;
$this->terms = $cache;
return $this->terms;
}
if ( 'count' == $_fields ) {

View File

@ -142,4 +142,27 @@ class Tests_Term_Query extends WP_UnitTestCase {
$clauses['orderby'] = 'ORDER BY tt.term_id';
return $clauses;
}
/**
* @ticket 37591
*/
public function test_terms_is_set() {
register_taxonomy( 'wptests_tax_1', 'post' );
self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
$q1 = new WP_Term_Query( array(
'taxonomy' => 'wptests_tax_1',
'hide_empty' => false
) );
$this->assertNotEmpty( $q1->terms );
$q2 = new WP_Term_Query( array(
'taxonomy' => 'wptests_tax_1',
'hide_empty' => false
) );
$this->assertNotEmpty( $q2->terms );
}
}