WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 4 months ago

#14502 new enhancement

Enable /post-type/taxonomy/term/ permalinks

Reported by: scribu Owned by:
Priority: normal Milestone: Future Release
Component: Rewrite Rules Version:
Severity: normal Keywords:
Cc: mikeschinkel@…, trac@…, johnbeales@…, travis@…, retlehs

Description

After we get /post-type/ handled (see #13818), it would be nice if we also had /post-type/taxonomy/term/ mapped to ?post_type=post-type&taxonomy=term

Change History (12)

comment:1 vteixeira3 years ago

Hi, thanks for creating this ticket.

That's exactly what's missing.

I just made a quick search and found that a lot of people are missing it.

See the comments of this post: http://www.cmurrayconsulting.com/software/wordpress-custom-post-type-archives/

comment:2 mikeschinkel3 years ago

  • Cc mikeschinkel@… added

comment:3 follow-up: scribu2 years ago

Turns out this is almost doable with WP 3.1's post type archives:

function shape_init() {
	register_taxonomy( 'shape-type', 'shape', array(
		'rewrite' => array( 'slug' => 'shapes/type' ),
		'label' => 'Shape Types'
	) );

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

The URLs would look like this:

/shapes/             # all shapes
/shapes/type/3d/     # 3d shapes only
/shapes/triangle/    # a singular shape

Another variation:

function shape_init() {
	register_post_type( 'shape', array(
		'has_archive' => 'shapes',
		'rewrite' => array( 'slug' => 'shapes/single' ),
		'public' => true,
		'label' => 'Shapes'
	) );

	register_taxonomy( 'shape-type', 'shape', array(
		'rewrite' => array( 'slug' => 'shapes' ),
		'label' => 'Shape Types'
	) );
}
add_action('init', 'shape_init');

Note: the post type has to be registered before the taxonomy.

Now, the URLs would be:

/shapes/                  # all shapes
/shapes/3d/               # 3d shapes only
/shapes/single/triangle/  # a singular shape

In both examples, the taxonomy is tied to a single post type.

comment:4 in reply to: ↑ 3 mikeschinkel2 years ago

Replying to scribu:

Turns out this is almost doable with WP 3.1's post type archives:...

Nice!

comment:5 vteixeira2 years ago

Hi Scribu, this is not a solution to the problem.

Simply because you are hardcoding the post type on the taxonomy slug, so it doesn't work.

This functionality is just needed because we need to have one taxonomy registered to different post types and we need to be able to filter those taxonomies by the post type on the url.

Your example works great for one taxonomy registered to one post type, but that was already possible...

The use case is:

Suppose I have two post types: Cars and Airplanes.
And one taxonomy: Color (registered for both post types).

I need to be able to call: 'site.com/cars/color/grey' and also 'site.com/airplanes/color/grey'.

And it should work as anyone would expect: filtering the taxonomy by the post type, as if I was calling 'site.com/?post_type=cars&color=grey' or 'site.com/?post_type=airplanes&color=grey'.

I'm not able to do this right now.

comment:6 scribu2 years ago

Yes, I know. That's why I said "almost".

comment:7 scribu2 years ago

Marked as dup: #16554

comment:8 ptahdunbar2 years ago

  • Cc trac@… added

comment:9 johnnyb12 months ago

  • Cc johnbeales@… added

comment:10 wpsmith9 months ago

  • Cc travis@… added

comment:11 dd328 months ago

  • Component changed from Permalinks to Rewrite Rules

comment:12 retlehs4 months ago

  • Cc retlehs added
Note: See TracTickets for help on using tickets.