[wp-trac] [WordPress Trac] #14502: Enable /post-type/taxonomy/term/ permalinks

WordPress Trac noreply at wordpress.org
Mon Jul 8 13:54:26 UTC 2013


#14502: Enable /post-type/taxonomy/term/ permalinks
---------------------------+-----------------------------
 Reporter:  scribu         |       Owner:
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Future Release
Component:  Rewrite Rules  |     Version:
 Severity:  normal         |  Resolution:
 Keywords:                 |
---------------------------+-----------------------------

Comment (by mboynes):

 Stumbled across this old ticket and figured I might be able to lend a
 hand.

 I think that this is doable with the current Rewrite API. You'd need to
 first add %post_type% as a rewrite tag, then use that in the taxonomy
 slug. You'd also want to prevent the taxonomy permastruct from creating
 rewrites for just %post_type%, so pass `'walk_dirs' => false` in the
 rewrite array.

 {{{
 function shape_init() {
         add_rewrite_tag( '%post_type%', '([^/]+)' );
         register_taxonomy( 'shape-type', 'shape', array(
                 'rewrite' => array(
                         'slug' => '%post_type%/type',
                         'walk_dirs' => false
                 ),
                 'label' => 'Shape Types'
         ) );

         register_post_type( 'shape', array(
                 'public' => true,
                 'has_archive' => true,
                 'label' => 'Shapes'
         ) );
 }
 add_action( 'init', 'shape_init' );
 }}}

 The only caveats that I can see are:

 1. Order is important. Here, the taxonomy must be registered before the
 post type.
 2. If you have a single shape with a slug of "type" it will cause some
 conflicts; it's post pagination would break, feeds would break, etc.,
 though the "single" view of /shape/type/ would work

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


More information about the wp-trac mailing list