EDIT Again, nope it's not impossible, just nasty. Solution below.
Trying very hard to get this working. Have tried numerous suggestions here on stackexchange/overflow
My goals are to simply select a 'page parent' on my custom post type and:
- Get permalinks displaying nicely, eg: /page/sub-page/sub-customposttype/
- One custom post type could have a different parent page to another custom post type.
- Get WordPress menu highlighting working, eg: it will apply an 'active' class to any parent menu items when viewing a child custom post type.
- (without hardcoding any page ids or custom slugs)
Here is the "Page" that I wish to make as parent: http://ultimateclientmanager.com/support/documentation-wiki/
Here is a "Wiki" custom post type that I wish to nest under that ^ page: http://ultimateclientmanager.com/support/documentation-wiki/change-request/
I have the "Wiki" custom post type slug set to 'support/documentation-wiki' in the code, this allows the permalink URL to look nice like above. However the 'wiki' does not have a parent selected, so menu highlighting does not work (and having different parent page urls for the wiki items would be impossible).
Here's some of my recent attempts on getting it to work.
- Set the "wiki" item post_parents to the ID of my "page".
- Leave the custom post type rewrite slug set to 'support/documentation-wiki'
- This generates a URL like: /support/documentation-wiki/support/documentation-wiki/change-request/
- This produces a 404 error.
- Debug shows query string of
wiki_page=support%2Fdocumentation-wiki%2Fchange-request&post_type=wiki_page&name=support%2Fdocumentation-wiki%2Fchange-request
- And a matched rewrite query of
wiki_page=support%2Fdocumentation-wiki%2Fchange-request&page=
and:
- Set the "wiki" item post_parents to the ID of my "page".
- Change the "wiki" post type slug back to just 'wiki' (instead of 'support/documentation-wiki')
- This generates a URL like: /wiki/support/documentation-wiki/change-request/
- This produces a 404 error.
- Debug shows query string of
wiki_page=support%2Fdocumentation-wiki%2Fchange-request&post_type=wiki_page&name=support%2Fdocumentation-wiki%2Fchange-request
- And a matched rewrite query of
wiki_page=support%2Fdocumentation-wiki%2Fchange-request&page=
and a desperate attempt to get the correct URL displaying:
- Set the "wiki" item post_parents to the ID of my "page".
- Change the "wiki" post type slug back to just 'wiki' (instead of 'support/documentation-wiki')
- Hack wp_rewrite during the 'wp' hook, change the struct from '/wiki/%wiki_page%' to just '%wiki_page%' like: like:
$wp_rewrite->extra_permastructs['wiki_page']['struct'] = '%wiki_page%';
- This generates a correct URL like: /support/documentation-wiki/change-request/
- But this also produces a 404 error because there it doesn't match anything in the query:
pagename=support%2Fdocumentation-wiki%2Fchange-request&page=
The parent page correctly shows up in the admin "wiki" listing and editing area, just do not seem to be getting anywhere in the frontend.
Current permalink settings are just Day and name http://ultimateclientmanager.com/2013/04/04/sample-post/
This is 3.5.1 setup as multisite.
post_parent
is a set of wiki articles can be grouped under different 'pages', and withpost_parent
set hopefully wordpress would manage all the multi-level menu highlighting without the nav css filter.get_page_by_path()
function. Yes it is impossible for wordpress to load a URL that contains nested mixed post types when the post_parent is set (eg: /a-page/another-page/a-custom-post-type ). This function will only return a valid page if all nested URL items are of the same post_type. oh well