Make WordPress Core

Opened 14 years ago

Last modified 6 years ago

#16832 new defect (bug)

Trouble if the slug of a custom taxonomy is the same as the url of page/post

Reported by: lucashantz's profile LucasHantz Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Rewrite Rules Keywords: needs-patch
Focuses: Cc:

Description

I got some troubles with the 3.1 version of WordPress concerning the slug of custom taxonomy.

An example that work in 3.0.5
www.example.com/agency (url of a page)
www.example.com/agency/john-smith (url of a custom type's detail)

Apparently having the same "folder" 'agency' only works for one or the other url but not both.

Hope I made myself clear.

Change History (13)

#1 @scribu
14 years ago

  • Keywords needs-patch added

You can use the 'wp_unique_post_slug_is_bad_flat_slug' filter to prevent collisions.

WP should handle that case automatically, though.

#2 @sterlo
14 years ago

I've had the same issue.

If the problem is that you have a folder called "agency" and a taxonomy called "agency" and it's choosing the folder over the taxonomy - you need to use wp_rewrite to tell it what it should be doing.

#3 follow-up: @scribu
14 years ago

@sterlo: That's different. First of all, WP always gives way to actual files. Secondly, WP doesn't have a taxonomy index, so /agency/ would return a 404 anyway.

#4 in reply to: ↑ 3 @sterlo
14 years ago

Replying to scribu:

@sterlo: That's different. First of all, WP always gives way to actual files. Secondly, WP doesn't have a taxonomy index, so /agency/ would return a 404 anyway.

WordPress by "Default" does not have a taxonomy index.

You can add it and it won't return a 404.

If he tries to get to page www.example.com/agency <- by default the page would show.

If he tries to go to www.example.com/agency/john-smith <- by default the taxonomy shows.

He could make www.example.com/agency point to the taxonomy still or whatever he wants it to point to for that matter - a file/page/taxonomy etc.

#5 @scribu
14 years ago

Sure, but my first point still stands. The default .htaccess rules prevent WP from loading when a file or directory is present at a certain URL. That's not going to change.

#6 @mikeschinkel
14 years ago

  • Cc mikeschinkel@… added

#7 @andrewryno
14 years ago

Not sure if it's related but I'm running into an issue that may stem from this.

I have one page at /work/. There are subpages of that main page (for example /work/philosophy/) as well as post types that use that same slug (/work/work-name/) and it's colliding. When trying to access a subpage, it returns a 404 because it is looking for a post within that post type.

Not the best architecture, I admit, but it might be possible for WP to search for subpages if it can't find a post for that post type (and if it has the same slugs). Though I'm probably going to just change the way I am doing things, just thought I'd add this.

#8 @tomauger
13 years ago

I might take a crack at this since it's something I'm running into a lot - basically in the context of wanting to create a main "taxonomy" landing page - both as a menu item and as a sort of meta-archive, such that if I go to /blog/my-custom-tax/ I can get an archive page that lists all the terms in that taxonomy. It would be best if this page's URL were the same as the tax's rewrite slug, for a better user experience in terms of the URI. /blog/my-custom-tax/term-one/ would of course be the archive page for a single term of the same taxonomy.

Okay, so before I even consider looking into this, I'd like to know, particularly from Scribu, what's the angle: get WP to enforce that a page slug can NOT be the same as the rewrite slug of a custom taxonomy? or figure out how to allow a "taxonomy landing page" type structure - whether it's a new kind of template file, or just a page that you manually assign a slug to like we do now, and figure out what, in the rewrite class is making it such that it gives us a 404 today?

#9 @scribu
13 years ago

With a clean WP 3.3 install, I can create a /tags/ page with a custom template and also have /tags/foo/ for a single tag. It just works.

If this doesn't work for custom taxonomies, it's a bug, IMO.

For custom post types, it's not so clear cut, since they can have dedicated archives.

Version 0, edited 13 years ago by scribu (next)

#10 @husobj
10 years ago

I have been doing some work relating to this but with post type archives.

With post archives, the intended behaviour is currently that if a post type archive exists at the same URL as a page, then the archive is displayed. An example of this as expected behaviour is where you set the 'blog' home page in WordPress Reading settings by selecting a page to use as page for posts (ie post archive page).

I've been working on a plugin that would allows you to set post type archive URLs based on pages for custom post types (although at present they need to support it via a filter), and optionally allow you to display the content from the page with matching URL in the header of the post archive page above the posts.

Terms current don't have a 'taxonomy' landing page so you can currently display terms as subpages of a page as mentioned by @scribu.

If adding support for term archive (or taxonomy) pages, i would suggest they follow a similar principle to post types:

  • register_taxonomy() would have a 'has_archive' parameter.
  • any rewrite rules would supercede pages rules so a term archive would be displayed rather than an existing page.

Just my thoughts... :)

#11 @husobj
10 years ago

Related to #13816 ?

#12 @chriscct7
9 years ago

WP could autofeed all of the registered taxonomy slugs through wp_unique_post_slug_is_bad_flat_slug

This ticket was mentioned in Slack in #core by helen. View the logs.


9 years ago

Note: See TracTickets for help on using tickets.