I recently stumbled across an issue on a site that uses the following URL structure;
/%postname%/%post_id%/
An old blog entry had the URL www.mysite.com/my-blog-post/1918/
Since that entry was made there was some media added to the site with the name My Blog Post, meaning the slug for it was also my-blog-post.
Since the addition of the media anyone going to www.thesite.com/my-blog-post/1918/ would be shown the media page instead of the blog page.
I can’t see this happening too often, I have corrected the error and informed the guys in charge of content to be mindful of it but it got me thinking about the precedence of different item types.
I would have thought off the bat that Media types would be lower down the list, but apparently not.
What I would like to know is how I go about finding what the precendence of WordPress items is and if there is any way of changing it.
The precedence is determined by the order of the rewrite rules:
http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/class-wp.php#L196
These map the structure to a query, which is then fed to
WP_Query
, which has its own defaults. I don’t see why you would be landing onto the media post, thepost_id
does not match, there should not be any collision in the first place. This does not appear to be undefined behavior, rather a bug in the rewrite rules, caused by some plugins or the theme etc. I assume that there’s a rewrite rule at the top which makes/pagename/.*/
fetch media post types.Dump the rules (
var_dump( get_rewrite_rules() )
) and see if anything makes sense.Further reading: