I have a custom post type in place that handles a guide to using a site. It covers everything a user would need to know about registering on a site, plus some other details.

I'd like to add some sub-guides to the site. I'd like them to mimic the URL structure of their parent guide.

Let's pretend it was a guide to Facebook. My custom post has the URL mysite.com/facebook-guide. Also, I want to add a sub-guide that has details on Facebook privacy. I want the URL to be mysite.com/facebook/privacy.

At the moment this isn't possible, as my 'guide' custom post type doesn't have the attributes box to set a parent. And if I use a standard page, the 'guides' won't show up in the drop down of existing content when setting a parent.

Is it feasible to do what I'm asking? If there is something I need to elaborate on, please let me know.

  • I feel it is possible. Could you post what code you have tried/have in your project so that we can get a better understanding of where it is your getting stuck. – EBennett Sep 7 '16 at 13:15

Yes, a posts parent_id is the ID of the parent post. There is no restriction on the type of post linked to, so from a data point of view, yes you can do this, and it has been done elsewhere, but it isn't common.

From a UI and URL point of view though, you will need to do work. You will need to build the selection UI. Luckily it can take the same format and input names as the existing UI, but when building you would supply different options to the control and render it yourself, rather than using a helper function or the existing control. You'd do this the same was as any other drop down box in a custom metabox, save for the name of the dropdown input. Note that plugins such as ACF will not help you here unless specifically built to do this.

For the URLs, you'll need to write some custom URL rewrite rules. The hard part is getting a regular expression for the URL you want to match against that works. You will also need to filter the permalinks of these guide posts so that they contain the correct full URL rather than the shorter direct URL without the parent guide.

| improve this answer | |
  • Thanks Tom. I'm pretty new when it comes to the nitty gritty changes to Wordpress. Any advice on where to start or which files to modify? – Mike Lovatt Sep 7 '16 at 14:02
  • You wouldn't modify Core, all of this is new code, you'll need a metabox, to register a new rewrite rule, and a filter to adjust the permalink. Those are 3 separate tasks, and out of scope of the question ( and would make good independent questions by themselves ) – Tom J Nowell Sep 7 '16 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.