You haven’t told us what sort of permalink you’re after. I’m guessing it’s like this:
example.com/parent-post/child-post/grand-child-post/
Such a permalink going 404 without special handling would be expected. The variable length nature of this permastruct makes rewrite rules difficult.
OTOH, if what you’re after is simply
example.com/grand-child-post/
and it’s going 404, then that is something else entirely. There is a glitch with your installation. This should work by default with any “pretty” permastruct.
I’m not very good with rewrite rules, but I think something like this might work (untested):
function custom_rewrite_rule() {
add_rewrite_rule('/([^/]*)/?$','index.php?name=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule');
Don’t forget to flush 😉
Thread Starter
allm
(@realblueorange)
@bcworkz
Thanks for looking into this!
While registering the custom post I use this as one of the arguments:
'rewrite' => array(
'slug' => '/abc',
'with_front' => false,
'feeds' => false,
'pages'=> false
),
This will result in permalinks like:
http://www.example.com/abc/postslug
http://www.example.com/abc/postslug/childslug
and so on.
The default rewrite rules that are being generated for handling this do not match the permalinks that WordPress itself generates. That sounds strange to me.
I’ll have a look at writing my own rewrite rules (new territory), but one would expect that WordPress generates the rewrite rules that match the permalinks that it generates.
Thanks for the piece of code you provided. I’ll have a go at that. I’ll also have a look at “ep_mask” that is one of the arguments when registering the custom post…
Any more ideas are welcome. If I get this fixed I’ll report it here. And if not I will go with a flat custom post structure and fix it another way…