[wp-trac] [WordPress Trac] #13490: Permalinks Issues for Custom Post Types with Parents

WordPress Trac wp-trac at lists.automattic.com
Sat May 22 23:03:29 UTC 2010


#13490: Permalinks Issues for Custom Post Types with Parents
--------------------------+-------------------------------------------------
 Reporter:  mikeschinkel  |       Owner:                   
     Type:  defect (bug)  |      Status:  new              
 Priority:  normal        |   Milestone:  Unassigned       
Component:  Post Types    |     Version:  3.0              
 Severity:  normal        |    Keywords:  reporter-feedback
--------------------------+-------------------------------------------------

Comment(by mikeschinkel):

 Okay, so I put some more time into this and am further confirming my
 concerns. (However, if I'm doing it wrong I will be graciously happy to
 learn of what I am doing wrong.)

 So I've updated the code to look like this:

 {{{
 add_action('init', 'tyc_post_types');
 function tyc_post_types() {
         global $wp,$wp_rewrite;
         $wp->add_query_var('restaurant');
         $wp_rewrite->add_rewrite_tag('%restaurant%',
 '([^/]+)','restaurant=');

         register_post_type('restaurant-menu',
                 array(
                         'label'           => __('Menus'),
                         'singular_label'  => __('Menu'),
                         'public'          => true,
                         'show_ui'         => true,
                         'query_var'       => 'restaurant-menu',
                         'rewrite'         => array('slug' => 'restaurant-
 menus'),
                         'hierarchical'    => true,
                         'supports'        => array(
                                 'title',
                                 ),
                         )
         );

         $wp->add_query_var('restaurant-menu');
         $wp_rewrite->add_rewrite_tag('%restaurant-menu%',
 '([^/]+)','restaurant-menu=');
         $wp_rewrite->add_permastruct('restaurant-menu',
 'restaurants/%restaurant%/menus/%restaurant-menu%');

         register_post_type('restaurant-location',
                 array(
                         'label'           => __('Locations'),
                         'singular_label'  => __('Location'),
                         'public'          => true,
                         'show_ui'         => true,
                         'query_var'       => 'restaurant-location',
                         'rewrite'         => array('slug' => 'restaurant-
 locations'),
                         'hierarchical'    => true,
                         'supports'        => array(
                                 'title',
                                 'editor',
                                 'excerpt',
                                 'custom-fields',
                                 ),
                         )
         );

         $wp->add_query_var('restaurant-location');
         $wp_rewrite->add_rewrite_tag('%restaurant-location%',
 '([^/]+)','restaurant-location=');
         $wp_rewrite->add_permastruct('restaurant-location',
 'restaurants/%restaurant%/%restaurant-location%');

         register_post_type('restaurant',
                 array(
                         'label'           => __('Restaurants'),
                         'singular_label'  => __('Restaurant'),
                         'public'          => true,
                         'show_ui'         => true,
                         'query_var'       => 'restaurant',
                         'rewrite'         => array('slug' =>
 'restaurants'),
                         'hierarchical'    => true,
                         'supports'        => array(
                                 'title',
                                 'excerpts',
                                 'thumbnail',
                                 'custom-fields',
                                 'editor',
                                 ),
                         )
         );
         global $wp_rewrite;
         $wp_rewrite->flush_rules(false);

 }
 }}}

 With this code this URL for Restaurant Menus works (I've not yet tried to
 get Restaurant Locations to work yet):

 {{{
 http://thetasteyoucrave.dev/restaurants/basmatis/menus/dinner-menu/
 }}}

 But the edit screen has this as a URL (where "dinner-menu" is editable)
 and the "View Menu" has the same link and of course doesn't work:

 {{{
 http://thetasteyoucrave.dev/restaurants/%restaurant%/menus/basmatis
 /dinner-menu/
 }}}

 As they say, pictures are worth 1000 words so here is the edit screen:

 [[Image(http://img.skitch.com/20100522-q6bxt9c18jhnsmpgqt8feb1hyf.png)]]

 And here's after clicking the "View Menu" button link:

 [[Image(http://img.skitch.com/20100522-jjsw8dsjmr1jc72fsw799685dc.png)]]

 I tried correcting the problem with a `post_type_link` hook modifying only
 a "sample" link but it didn't help; results were the same.

 '''It seems the major culprits here are the `get_sample_permalink()`
 and/or the `get_sample_permalink_html()` functions.'''

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


More information about the wp-trac mailing list