diff --git a/src/wp-includes/taxonomy-functions.php b/src/wp-includes/taxonomy-functions.php index 8a80184197..eee37bc8a3 100644 --- a/src/wp-includes/taxonomy-functions.php +++ b/src/wp-includes/taxonomy-functions.php @@ -803,8 +803,9 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw $field = 'tt.term_taxonomy_id'; } else { $term = get_term( (int) $value, $taxonomy, $output, $filter ); - if ( is_wp_error( $term ) ) + if ( is_wp_error( $term ) || is_null( $term ) ) { $term = false; + } return $term; } diff --git a/tests/phpunit/tests/term.php b/tests/phpunit/tests/term.php index 60409dda15..bd050c55b0 100644 --- a/tests/phpunit/tests/term.php +++ b/tests/phpunit/tests/term.php @@ -57,6 +57,14 @@ class Tests_Term extends WP_UnitTestCase { $this->assertEquals( get_term( $term1['term_id'], 'category' ), $term2 ); } + /** + * @ticket 33281 + */ + function test_get_term_by_with_nonexistent_id_should_return_false() { + $term = get_term_by( 'id', 123456, 'category' ); + $this->assertFalse( $term ); + } + /** * @ticket 15919 */