[wp-trac] [WordPress Trac] #16323: Hierarchical CPTs without a custom query_var 404 (was: Hierarchical Custom Post Type Bug - invalid name query var generated)

WordPress Trac noreply at wordpress.org
Fri Aug 9 13:55:23 UTC 2013


#16323: Hierarchical CPTs without a custom query_var 404
--------------------------+------------------------------
 Reporter:  jrcowher      |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  3.0.4
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |
--------------------------+------------------------------
Changes (by duck_):

 * component:  Permalinks => Query


Comment:

 The problem here is that hierarchical post types that have been registered
 without a `query_var` will 404 when requesting child items. This occurs
 because the `name` query var is not mapped to `pagename` if the post type
 `query_var` doesn't exist. Simplified
 [http://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/query.php?annotate=blame&rev=25001#L2082 from WP_Query]:

 {{{
 foreach ( (array)$q['post_type'] as $_post_type ) {
   $ptype_obj = get_post_type_object($_post_type);
   if ( !$ptype_obj || !$ptype_obj->query_var || empty($q[
 $ptype_obj->query_var ]) )
     continue;

   if ( $ptype_obj->hierarchical && strpos($q[ $ptype_obj->query_var ],
 '/') !== false ) {
     $q['pagename'] = $q[ $ptype_obj->query_var ];
     $q['name'] = '';
   }
 }
 }}}

 With `pagename` not set the path is not sent through `get_page_by_path()`,
 but directly queried as the post_name after sanitisation.

 This code originates from [14072] for #12704.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/16323#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list