diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 8cbef3c718..9865f42be7 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -390,6 +390,9 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { else $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); $wp->add_query_var( $args['query_var'] ); + } else { + // Force query_var to false for non-public taxonomies. + $args['query_var'] = false; } if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 2063bbe333..0cf65169e1 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -517,4 +517,17 @@ class Tests_Taxonomy extends WP_UnitTestCase { $this->assertFalse( is_tax( 'wptests_tax' ) ); } + + /** + * @ticket 35089 + */ + public function test_query_var_should_be_forced_to_false_for_non_public_taxonomy() { + register_taxonomy( 'wptests_tax', 'post', array( + 'public' => false, + 'query_var' => true, + ) ); + + $tax = get_taxonomy( 'wptests_tax' ); + $this->assertFalse( $tax->query_var ); + } }