I have a custom post type whose permalink needs to sit in the same space as pages, like so:

/an-example-thing  <--  custom post type 'thing'
/about-the-things  <--  a normal page

I’m well aware that this isn’t the recommended way to do it, but I don’t really have a choice – that’s what the client has specified.

I’ve created the custom types with register_post_type, and used the Custom Post Permalinks plugin to set their permalink like so:

/%thing%/

However, this creates a conflict between the rule that recognises my custom posts, and the one for normal pages – which turns all normal pages into 404s. This problem disappears when the permalink is changed to something like this:

/things/%thing%/

Using the Monkeyman Rewrite Analyser shows that the rule for the custom post is coming first. Even when I try forcing it to use verbose rules:

global $wp_rewrite;
$wp_rewrite->use_verbose_page_rules = true;

the custom post type rule is higher priority than the verbose rules for pages so they still get a 404.

I’d like it to look for things first, and when none is found with that name look for pages. The other way round would be acceptable. Is there no way of persuading it to look for both things and pages before hitting a 404?

3 Answers
3

You start with one bonus point for using my rewrite analyzer 🙂

Indeed, even if you use verbose page rules, since version 3.1 (or something around that) the taxonomy rewrite rules come even before that. I recently answered another question with a way to move them really to the top. This should work if you don’t mind having verbose page rules (if you don’t have more than 25 pages or so).

If you don’t want verbose page rules you will have to extend the core WP class so it can deal with “ambiguous” situations where the URL can refer to a page or a custom post type. Mike once provided a nice way to do this. His answer is written for a custom taxonomy, but it should be adaptable to a custom post type too.

Leave a Reply

Your email address will not be published. Required fields are marked *