This one is tricky, I’ve got Custom Post Type called “dictionary”, users add “definitions” there which are automagically put into right categories (so for example if user adds “Apple” it’s under “A”).
The URLs look like this:
- blog/dictionary/ – dictionary welcome page
- blog/dictionary/x/ – listing of definitions starting with “x” letter
- blog/dictionary/x/Xavier – definition of word “Xavier”
Now, I want to add normal WordPress pages and somehow display them under:
- blog/dictionary/rules
- blog/dictionary/author
etc.
I’m creating new pages and setting “Dictionary” page (blog/dictionary) as their parent, so they’re where they supposed to be, but display NOTHING AT ALL, no content, nothing. I have absolutely no idea how to resolve it. I can’t add them to “dictionary” custom post type as it holds definitions only.
Any ideas? I’d rather avoid mod_rewrite (as I want my pages to be children of “dictionary” not hard-linked normal pages).
In short words: I need two types of elements under one Custom Post Type.
UPDATE
Looks like when my “dictionary” is a a child itself it works, for example:
- blog/dictionary/authors – displays nothing
- blog/page1/dictionary/authors – displays authors page
Why is that?
If it were me, here’s how I’d achieve this.
Preface
Assuming the following data structures:
And the desired URLs:
1. Set the post type and taxonomy urls
When registering your post type, the
rewrite
param should be,When registering your taxonomy, the
rewrite
param should be,You need to filter
post_type_link
because of the rewrite tag (%dictionary_category%
) in the rewrite slug. Here’s what that would look like:Now, /dictionary/x/ works and /dictionary/x/xavier/ works.
2. Set the page URLs
Here, we’re going to take advantage of the fact that the dictionary_category terms won’t ever be more than 1 character. Anything after /dictionary/ and more than one character will be assumed to be a page.
Flush your rewrite rules (Go to Settings → Permalinks and click “Save Changes”), and everything should work as desired.
Notes
wpse_119806_rewrite_rules
with additional calls toadd_rewrite_rule()
.