0

I have a custom post type "E-Books" with two categories "E-Book Title" and "Chapter Page", and custom meta boxes (table of contents, etc).

The E-Book post type uses one page template, and displays content based on category conditional.

<?php if (in_category('e-book-title')) { content } ?>

The "E-Book Title" posts are the parents and all meta info will be stored on these posts.

The "Chapter Page" posts are children of their respective "E-Book Title", and I would like each chapter page to grab the meta values of their parent.

For example, the table of contents meta will be stored for the title page "Book One", and when a new chapter post "Chapter One" is created with the assigned parent "Book One", the meta values from "Book One" will be stored for the new chapter post.

Is there a way to do this? I could manually enter the meta values in the chapter posts, but would be much user friendly if the chapter posts inherited their parents meta automatically.

  • you could do this by saying if no meta use parent meta or you could say if there is a parent post use parent meta otherwise use meta of this post. – rudtek Dec 28 '18 at 22:28
  • Putting the parents meta in the child posts sounds unneccessarily complicated, especially when you consider that you would have to hook into any changes in the parent and update the children, and then do the same in reverse. Why not just do a get_post_meta call but pass the parent ID in the template? So much easier, if you're unsure how to do that, it's rather easy just ask how on the site – Tom J Nowell Dec 29 '18 at 0:48

Your Answer

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

Browse other questions tagged or ask your own question.