I recently stumbled across an issue on a site that uses the following URL structure;


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.

1 Answer 1


The precedence is determined by the order of the rewrite rules:


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, the post_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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.