Skip Navigation

[Resolved] How to display CPTs within another CPT

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user has a Parent post but wanted to display the related child posts on that Parent page.

Solution:

To do this I recommend taking a look at the page below.
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/#3-creating-a-view-that-lists-the-children-of-the-parent-post

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by benE-3 5 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#1193866
mockup.jpg

I have custom post types for Books and Articles. I want to create a page that aggregates each of these CPTs by subtopic (see attached mockup) and displays 2 books and 1 article. A book or article may appear in more than one subtopic.

I've done something similar with Advanced Custom Fields before, where I created a CPT called Subtopics and selected the appropriate Books and Articles as children. Reading through Toolset's documentation, I don't think it can be done this way. Instead, I'm trying to create a View.

Questions:

Am I write that I can't do this with Toolset by creating a parent CPT for Subtopics? That would be my preferred method if it's doable.

Alternately, if using Views I'm guessing they'll need to be nested... Books and Articles within Subtopics within the Topic page.

I've been searching through Toolset's forums and documentation, but would appreciate any guidance on how to best do this.

Thank you!

#1193931

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ben,

Thank you for contacting our support forum.

The Correct Way to do this is to have the Topic as the Parent CPT and Subtopic the child and then book and article being Children of subtopic.

With a Relationship setup you should be able to achieve this using our Views plugin to display the correct relationship information by nesting the views.

Are you aware of how to set all this up correctly?

Please let me know.

Thanks,
Shane

#1196284

I set up my custom post types with the appropriate relationships and had no problem creating a view to display Books:

hidden link

I'm now trying to create a Parent View that displays the Title of each Subtopic following by the Books View displaying just the Books in that Subtopic, so I can loop through the Subtopics.

I've been following this article:

https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

But having a hard time figuring it out.

Any help appreciated. Thanks!

#1196291

By way of example, here's a page where I'm displaying each Subtopic title:

hidden link

But the Books View pulls the same 3 books regardless what Subtopic I'm looping through (even though I've set up Relationships for each Book). I know I can filter the Books directly in my Books View, but that would mean creating a Books View for each Subtopic. How can I tell the Books View to pull the Books for the Subtopic. Here's my Loop Wizard code:

[wpv-layout-start]	
  [wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          [wpv-post-title]
          [wpv-view name="books"]
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]
#1196316

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ben,

Happy to see there is some progress.

From your links and explanation I see that you've added the books view to your subtopics view.

To get the appropriate book for the subtopic to be displayed you will need to add a Post Parent query filter to the Book view.
There is an example here
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/#user-view-with-a-post-view-for-a-child

The example talks about the Post Author filter but instead of Post Author you will use the Post Parent filter then select "Parent is the current post in the loop"

This should start allowing your items to display based on the Subtopic. If this does not work please let me know.

Thanks,
Shane

#1196329
post-parent-filter.jpg

That sounds exactly like what I'm trying to do!

I added a Post Parent Filter to the Books View, but now it says No Items Found:

hidden link

I double checked that each Book is in a child relationship to a Subtopic. I have a couple Subtopics with no Books assigned, but the Sample Content Subtopic and Intro to Civic Engagement both have Books assigned to them.

Screenshot of my Post Parent Filter settings for the Books CPT attached.

Thank you for your help!

#1196351

Thanks so much for your help!

I needed to select "Post relationship or repeatable field groups owner" and then the other options.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.