33 Responses

  1. Luis Sanchez Perez
    Luis Sanchez Perez Published |

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

    Reply
  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).

    Reply
  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.

    Reply
  4. Ben
    Ben Published |

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

    What’s your take on this approach?

    Reply
  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 |

    Awesome.

    Have you watch this video ?

    http://wordpress.tv/2013/08/24/matt-boynes-rewrite-recipes-exploring-advanced-permalink-structures-by-example/

    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.

    Reply
  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.

    Reply
  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!

    Reply
  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

    Reply
  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.

    Reply
  13. Kevin
    Kevin Published |

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

    Reply
  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

    Reply
  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. :)

    Reply
    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.

      Reply
      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

    Reply
  17. Jason Miller
    Jason Miller Published |

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

    Reply
  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.

    Reply
  20. Prashant
    Prashant Published |

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

    Reply
  21. Marcos
    Marcos Published |

    Ty, works for me ;)

    Reply
  22. Mickey
    Mickey Published |

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

    Reply
  23. Tareq059
    Tareq059 Published |

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

    Reply
  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?

    Reply

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.

css.php