Ticket #19744: 19744.2.diff
| File 19744.2.diff, 3.5 KB (added by , 12 years ago) |
|---|
-
src/wp-includes/class-wp.php
238 238 239 239 $this->public_query_vars = apply_filters('query_vars', $this->public_query_vars); 240 240 241 foreach ( $GLOBALS['wp_post_types']as $post_type => $t )241 foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) 242 242 if ( $t->query_var ) 243 243 $post_type_query_vars[$t->query_var] = $post_type; 244 244 … … 271 271 } 272 272 273 273 // Convert urldecoded spaces back into + 274 foreach ( $GLOBALS['wp_taxonomies']as $taxonomy => $t )274 foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t ) 275 275 if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) ) 276 276 $this->query_vars[$t->query_var] = str_replace( ' ', '+', $this->query_vars[$t->query_var] ); 277 277 -
src/wp-includes/query.php
1735 1735 ); 1736 1736 } 1737 1737 1738 foreach ( $GLOBALS['wp_taxonomies']as $taxonomy => $t ) {1738 foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t ) { 1739 1739 if ( 'post_tag' == $taxonomy ) 1740 1740 continue; // Handled further down in the $q['tag'] block 1741 1741 -
src/wp-includes/rewrite.php
338 338 $url = trim($url, '/'); 339 339 340 340 $request = $url; 341 $post_type_query_vars = array(); 341 342 343 foreach ( get_post_types( array() , 'objects' ) as $post_type => $t ) { 344 if ( ! empty( $t->query_var ) ) 345 $post_type_query_vars[ $t->query_var ] = $post_type; 346 } 347 342 348 // Look for matches. 343 349 $request_match = $request; 344 350 foreach ( (array)$rewrite as $match => $query) { … … 365 371 366 372 // Filter out non-public query vars 367 373 global $wp; 368 parse_str( $query, $query_vars);374 parse_str( $query, $query_vars ); 369 375 $query = array(); 370 376 foreach ( (array) $query_vars as $key => $value ) { 371 if ( in_array( $key, $wp->public_query_vars) )377 if ( in_array( $key, $wp->public_query_vars ) ){ 372 378 $query[$key] = $value; 379 if ( isset( $post_type_query_vars[$key] ) ) { 380 $query['post_type'] = $post_type_query_vars[$key]; 381 $query['name'] = $value; 382 } 383 } 373 384 } 374 385 375 386 // Do the query 376 $query = new WP_Query( $query);377 if ( ! empty($query->posts) && $query->is_singular )387 $query = new WP_Query( $query ); 388 if ( ! empty( $query->posts ) && $query->is_singular ) 378 389 return $query->post->ID; 379 390 else 380 391 return 0; -
tests/phpunit/tests/rewrite.php
32 32 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 33 33 } 34 34 35 function test_url_to_postid_custom_post_type() { 36 delete_option( 'rewrite_rules' ); 37 38 $post_type = rand_str( 12 ); 39 register_post_type( $post_type, array( 'public' => true ) ); 40 41 $id = $this->factory->post->create( array( 'post_type' => $post_type ) ); 42 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 43 44 _unregister_post_type( $post_type ); 45 } 46 35 47 function test_url_to_postid_hierarchical() { 36 48 37 49 $parent_id = $this->factory->post->create( array( 'post_title' => 'Parent', 'post_type' => 'page' ) );