47 Responses

  1. Luis Sanchez Perez
    Luis Sanchez Perez Published |

    Excellent tutorial. Thanks for these tutorials for wordpress. I love them.

  2. Hayley
    Hayley Published |

    Just been playing with this stuff myself since bbPress runs off parent-child custom post types (with topics and forums both being types of post, for those not in the know). Kinda nifty. The Posts 2 Posts plugin is definitely interesting, but I notice scribu says he won’t be supporting it anymore, and is hoping to hand it over to someone (http://scribu.net/wordpress/posts-to-posts/version-1-6.html).

  3. Randy
    Randy Published |

    I guess I am just wondering the obvious of why not use a taxonomy for the neighborhoods? What happens if there is more than one of the same place(ie – a chain of restaurants) then you are re-creating each place for each neighborhood? Perhaps if I knew the full scope of the project I’d get this reasoning.

  4. Ben
    Ben Published |

    Justin, have you seen the CPT-onomies plugin from Rachel Carden?

    What’s your take on this approach?

  5. The Weekly WordPress News, Tutorials & Resources Roundup No.46 - WPLift
  6. Parent to child post relationships : Post Status
  7. David Chandra
    David Chandra Published |


    Have you watch this video ?


    more example than pro wp plugin dev book.

    but i recommend to read the book first. (or at least understand a little bit about permalink rewrite)

    all the fun stuff with unlimited possibilities to explore.

  8. Mary Susan
    Mary Susan Published |

    I must commend your tutoring skills on this website, thanks for this post on parent-child relationship on wordpress.

  9. Robin
    Robin Published |

    Thank you so much for this post–it came just when I needed it for a project!

    I’ve gotten single CPT pages set up for both parent and children, and the archive for parent and parent taxonomies. However, I’m having some issues with pulling parent meta data for use on child archive pages, was wondering if you or a reader could point me in the right direction–on child archives and taxonomies, I would like to order the results by one of the parent’s meta keys, not by any child data. I’ve tried pulling the post_meta the same way I’ve done it (successfully) on single pages but it is not working in my args. Would appreciate any insight–and again, thank you for a clear way of establishing parent/child relationships between CPTs!

  10. Nile
    Nile Published |

    I can kind of see this as a cool step toward being able to make fiction sites (story sharing sites) and using this for chapters to the main post instead of relying on some type of plugin to bring them all together in with an index, or manually creating one. Just a thought…lol

  11. #WordPressWednesday 2013 Volume 10
    #WordPressWednesday 2013 Volume 10 at |
  12. charlie
    charlie Published |

    I’ve got a few places where I’m using relationships between posts. I achieve this using the Advanced Custom Fields plugin (which I can’t recommend more highly).

    The plugin’s ‘relationship’ field does this beautifully! The only coding I did was to write a simple filter to limit the list of posts displayed in the backend that the content-editor can select from.

  13. Kevin
    Kevin Published |

    The tutorial was much appreciated. I’m trying to figure out wordpress in depth so this was super helpful.

  14. Manny Fleurmond
    Manny Fleurmond Published |

    I’ve used this technique before for a plug-in I was working on which had cpt’s for TV shows, episodes and dvd releases. The parent child relationship only works up to a point: trying to connect episodes to releases required a many to many relationship, which is why I moved to Posts 2 Posts core. Really wish WP had something in core for cpt relationships

  15. Iva
    Iva Published |

    In a case like this, can a child, e.g. “Song” have two parents: Release and Show? I already have Release as another non-hierarchical post type, but I have Show as a taxonomy and I’m not too keen on that.

    Thanks for any tip. 🙂

    1. Manny Fleurmond
      Manny Fleurmond Published |

      With this trick, no. The parent child relationship is one to many : one patent can have many children but a child can only have one parent. This is because the post parent is saved on the child.

      1. Iva
        Iva Published |

        I assumed that would be the answer; but thank you. 🙂 Looking for a different solution, still.

  16. egyaqar
    egyaqar Published |

    good tutorial

    thank you so so so … much

  17. Jason Miller
    Jason Miller Published |

    I actually didn’t realise the parent-child relationship could work with posts! Thanks for sharing

  18. Theme and Plugin development | Sandboxx
    Theme and Plugin development | Sandboxx at |
  19. ibrahim aydın
    ibrahim aydın Published |

    codes have not been able to use them if you could help? Thanks.

  20. Prashant
    Prashant Published |

    Lovely, never knew we can built parent-child relationship posts. Thanks Justin, going to try this.

  21. Marcos
    Marcos Published |

    Ty, works for me 😉

  22. Mickey
    Mickey Published |

    Any tips on displaying custom post types under parent pages in auto-generated menus?

  23. Tareq059
    Tareq059 Published |

    parent child relationship is a good practice. Applying this technique from the beginning of html learning… nice post..carry on.

  24. Benjamin Turner
    Benjamin Turner Published |

    I like this a lot and was able to get it to work on a project I’m working on.

    One question I have which is more along the lines of ‘deeper understanding’ — How does the above code ‘know’ what info to save?

    From my understanding, metaboxes need 3 things to work:

    register the metabox

    callback function to display the HTML

    function to save / sanitize the information to post_meta

    From the above code I can see the first two things — register the metabox and a function to render the HTML.

    I’m guessing the third thing — saving the info — has to do with the naming of ‘parent_id’.

    Is this some WordPress mojo / naming convention? If it is can you point me to more info on this topic?

  25. Luis Santander
    Luis Santander Published |

    Thanks for this tutorial. Pointed me to Posts 2 Posts plugin which was exactly what I needed. Wish there was native support for post relationships, but I guess we’ll have to wait. Thanks for the tutorial!

  26. kingstakh
    kingstakh Published |

    Nice tutorial! Thanx! But how get data for posts on home page from relations?


    Post Type: my parent post type

    Child Post Type: my child post type from my parent post type

    Custom Field: custom filed from child type

  27. Parent to child post relationships | Post Status
  28. Ed Kim
    Ed Kim Published |

    I was wondering if anyone had some alternative plugins ideas for Posts 2 Posts? It looks like an awesome plugin but it has been abandoned by it’s owner.

    BTW. I’ve used custom post types just long enough want a parent child relationship with some. I found your site because the Custom Post Type UI Plugin has some handy links in their plugin to your site.

  29. Alex
    Alex Published |

    I like the solution but I dont seem to be able to save any of the data im selecting.

    I can see the list of my posts from my custom post type in the meta box – great.

    But If i select an option, it will always default to the first option after I click update. Are you sure I dont need to add the save functionality,.


  30. Binh WPOS
    Binh WPOS Published |

    Hi Justin,

    Thanks for sharing this. I was scratching my head thinking I will have to build my own plugin to deal with relationships between posts. Luckily you mentioned about Posts 2 Posts plugin.

    I will try it and if possible, will contribute to improve it so that others can build a better structured site.


    Binh Nguyen

    Update: Please check. Somehow I missed the “Post Comment” button which was in grey (same as the input field) and clicked on “Next ->” button in white…

  31. h
    h Published |

    thanks for a great tutorial. i’ve linked to it on wordpress.stackexchange.com.

    But how to keep the admin menu clean it would be nice to have everything sit under one root entry like so?


    Add New


    I only know how to add a root level CPT. So mine looks like this:


    Add New


    Add New

  32. With two custom post types, how to make one sit under the other in admin menu? | DL-UAT
  33. With two custom post types, how to make one a child of the other in the admin menu? | DL-UAT
  34. ULVEN | Frontend Design and Development
  35. Caroline
    Caroline Published |

    Great tutorial!

    I was wondering, how would you display a list of the child posts assigned to the parent custom post type in the back end and front end?

Comments are closed.