Title: Nesting Custom Post Types
Last modified: April 10, 2019

---

# Nesting Custom Post Types

 *  Resolved [baldidiot](https://wordpress.org/support/users/baldidiot/)
 * (@baldidiot)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/nesting-custom-post-types/)
 * Is it possible to either nest custom post types or somehow use the custom rewrite
   to make them appear as though they are nested?
 * For example, let’s say we have two post types that have different custom fields
   and layouts – Food and Recipes.
 * Is it possible to have the URLs appear like this:
 * mysite.com/food/recipes/post/
 * I tried using the custom rewrite slug in the setting for the ‘recipes’ post type
   to ‘food/recipes’ and the URL appears correctly in the back end but the front
   end version shows a 404 error so guessing we can’t have a slash in this field?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [7 years, 1 month ago](https://wordpress.org/support/topic/nesting-custom-post-types/#post-11412811)
 * If I’m being completely honest, any time i see people try to put `/` characters
   in rewrite rules, i twitch a little. This is because it’s hijacking the rewrite
   slug field and stuffing more than what should be in there into it.
 * That said, I know you could get something like this with hierarchical post types,
   so you could get the parent/child relationships going. It wouldn’t be a mashup
   of 2 post types, it’d just use one. However, with enough content planning, you
   could make it appear as two.
 * Couple that in with something like [https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/](https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/)
   and you could easily select which templates each post uses an get the different
   layouts/meta detail covered.
 * At that point, I think you’d be in a pretty good spot.
 *  Thread Starter [baldidiot](https://wordpress.org/support/users/baldidiot/)
 * (@baldidiot)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/nesting-custom-post-types/#post-11413300)
 * Hi Michael,
 * Thanks for the quick reply. Ah, I see. So the only way to do it really would 
   be having one post type with multiple template versions?
 * In the example above we also have different sets of custom fields (using the 
   Advanced Custom Fields plug in) so one for Food and one for Recipes – this was
   one of the main reasons why we wanted to separate them into different post types.
 * This is where the bigger issue comes because the Food post type will be fairly
   normal with an editor, but the Recipes post type wouldn’t use the normal editor–
   instead it’s made up of modular fields. Eg: Intro / Ingredients List / Method/
   and so on…
 * It’s partially for continuity but also to allow us to add in extra bits – lists
   of where to buy products that have been selected as ingredients, auto switching
   between measurement types and so on.
 * Is there any way to nest one custom post type under another – Eg: Have Recipes
   as a child post type of Food?
 * Or is this just asking for the moon on a stick?..
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [7 years, 1 month ago](https://wordpress.org/support/topic/nesting-custom-post-types/#post-11413757)
 * I won’t claim the only way to handle this, but I will say that if I was tasked
   up with such a thing, my last reply would likely be how I start going about it.
 * I am not personally aware of any sort of way to create that type of nesting/parent-
   child between post types.
 * With the topic of ACF, I am thinking/wondering if you could set up conditional
   fields for this, and display some for certain case. Say even something as simple
   as a specific category/tag/taxonomy term being selected, which doesn’t even need
   to be displayed on the frontend. It’d just be a toggle of sorts for the fields.
 *  Thread Starter [baldidiot](https://wordpress.org/support/users/baldidiot/)
 * (@baldidiot)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/nesting-custom-post-types/#post-11422433)
 * Yes that’s what I was thinking as the only other way around – the fields can 
   be based on some kind of selector. Not quite as neat as I’d hoped but it’ll do
   the job!
 * Thanks again for the help and appreciate the work on the plug in, we use it all
   the time!
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [7 years, 1 month ago](https://wordpress.org/support/topic/nesting-custom-post-types/#post-11422547)
 * Glad to hear, thanks [@baldidiot](https://wordpress.org/support/users/baldidiot/)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Nesting Custom Post Types’ is closed to new replies.

 * ![](https://ps.w.org/custom-post-type-ui/assets/icon-256x256.png?rev=2744389)
 * [Custom Post Type UI](https://wordpress.org/plugins/custom-post-type-ui/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-post-type-ui/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-post-type-ui/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-post-type-ui/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-post-type-ui/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-post-type-ui/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [7 years, 1 month ago](https://wordpress.org/support/topic/nesting-custom-post-types/#post-11422547)
 * Status: resolved