Hi,
I have a CPT called "Books" and a child CPT called "Chapters.
I want to display a list of the chapters in the book post (i.e. child posts), as well as displaying a list of chapter in the chapters themselves (i.e. brohter posts).
The child posts view is easy and can be seen working here:
hidden link
you will see 2 chapter links.
I followed the tutorial for the brother post here, I even followed the content template names..etc
but nothing shows up at all in the chapters posts. it only shows the body text
(which I wrote as "chapter body text")
https://toolset.com/documentation/user-guides/displaying-brother-pages/
hidden link
hidden link
also, I am using layouts for all other CPT i have, while the tutorial only uses a content template.
so my questions are:
1- How to show the borther posts, as per the tutorial
2- How to use a layout for the Chapters CPT, not just a content template.
Thanks in advance.
In your content template (hidden link) you do use a View that does not exist at all in your system:
[wpv-view name="Tutorials Sidebar Parent"]
In your single chapter template, you call that View thru the Content Template of the supposed parent page (which as well does not exist for chapters as far as I see):
[wpv-post-body id="$parent" view_template="Tutorials Sidebar Parent"]
$parent means there should be a parent of the same post type set by a WordPress relationship as in pages.
Let me see if I can give a quick solution to the issue
I have a CPT called "Books" and a child CPT called "Chapters.
I want to display a list of the chapters in the book post (i.e. child posts), as well as displaying a list of chapter in the chapters themselves (i.e. brohter posts).
- I want to display a list of the chapters in the book post
Exactly as you state, and successfully did already, you create a View, and query Chapters. Then you add a Query Filter as in "Select posts that are children of the Post where this View is shown.". Then, you can insert this View to a Content Template, and assign this template to your Books Posts.
It will show all "child" chapters information that you added to the Views Loop.
- as well as displaying a list of chapter in the chapters themselves
Here you create a View, and query Chapters again.
You set a Query Filter as in "Select posts that are children of the Post with ID set by the shortcode attribute wpvprchildof.
eg. [wpv-view name="view-name" wpvprchildof="123"]", and make sure to check "Don't include current page in query result" in the "Query Options" if the view.
Then you insert this View to the Content Template you apply to Chapters.
Make sure to pass the ID of the current chapter to the View ShortCode attribute "wpvprchildof", like so:
[wpv-view name="related-chapters" wpvprchildof="[wpv-post-id id='$parent-book']"]
That should produce a list of chapters that are in the same book as the current chapter.
Hi Beda,
Thank you very much for your thorough checks.
I deleted the wrong content templates and created a new view as you said.
I Created a View called "Chapters Sibling Posts"
and pasted the following shortcode in the first chapter:
[wpv-view name="chapters-sibling-posts" wpvprchildof="[wpv-post-id id='$parent-book']"]
However, it gave a "No items found":
hidden link
For chapter 2, i tested the shortcode by adding the parent book id:
[wpv-view name="chapters-sibling-posts" wpvprchildof="[wpv-post-id id='1745']"]
This time a correct view showed with one chapter in it (i only have 2 test chapters)
hidden link
So the shortcode itself works, but the
[wpv-post-id id='$parent-book']
part is not working.
can you please review and suggest a fix?
thanks a lot.
Hi Beda,
Also, I tried to use the same principle to show the title of the parent book post, based on this tutorial:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
and used this code:
The title of the parent book:
[wpv-post-title id="$parent-book"]
But the result is the post title of the chapter post, not the parent book post:
hidden link
$parent-book has to be the slug of your parent type. You need to use the GUI to insert these codes if possible or make sure you adapt them to your system adequately.
Usually, the $ is a $parent for native post relation of pages in WordPress or, if added, in Custom Posts.
For Types relations, as you know from the GUI, it will be $parent_post_type_slug instead, where you need to change parent_post_type_slug to your real parent post type slug.