Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url

I have been reading dozens of posts and honestly, I have many doubts on how this work. Furthermore, I think that with WP3.1 more issues have been added here because I am having even more problems now than before.

The point is that I am using the same slug for different kind of taxonomies and posts. Let’s use loans as the slug for my problem.

Until now, I had the page /loans/ and also the category /loans/ and subs /loans/fixed-rate/ and /loans/variable-rate/. In /loans/ I displayed the page where I had a custom template showing different things and in /loans/subcategories/ I had archives for the posts in that given category. Furthermore, my posts had the strucutre /%postname%/.

Now, in WP3.1, in /loans/, I see the archive of all the posts in /loans/ and its children and I have been forced to create a category template “copying” what I had in the page before.

I want now, taking advantage of WP3.1 features, to create a custom post called also /loans/ so I can define a new template for these posts. I also want to create a new taxonomy called /loans/ (instead of the category) being non-hierarchical so I can have dozens of subcategories /loans/loans-bank-X/, loans/loans-X-rate/, /loans/loans-X-years/ :

  • /loans/ -> Page with a custom template
  • /loans/fixed-rate/, /loans/bank-of-america/, /loans/30-years/ -> Taxonomy
  • /loans/30-years-fixed-rate-loan-of-bank-of-america-review/ -> Custom Post with a review of the product

¿Is there a way of doing this correctly?

I had read before thag pages had priority over categories but not now in 3.1. I believe it would also be nice if someone write down the current priority of these slugs.

This can be solved using different slugs for the taxonomies, etc but from a SEO and UX point of view it is much better to do it with the same slug.

Thanks a lot and regards.

Solutions Collecting From Web of "Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url"

WordPress parses incoming URLs with a list of regular expressions, the rewrite rules. The first regex that matches the URL “wins”, and determines what kind of query will be executed. You can see the rewrite rules and play with different URLs with my Rewrite analyzer plugin.

Whether or not pages take priority over other rules depends on your permalink structure. If it contains %postname%, %category%, %tag%, or %author% as the first permastruct, the rewrite engine will generate verbose page rules, where each page gets a specific rule at the top of the list instead of a catch-all rule at the end. This can explain the difference between the two sites.

The WP_Rewrite::rewrite_rules() function that generates the rules has many different filters. You can hook into one of them to modify the array, so that the most important rules for you are at the top. You can find many questions on this site with examples of how to modify these rules.