Skip Navigation

[Resolved] Link to CPT view based on post relationship

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

Problem: I have a one-to-many hierarchical relationship of post types with grandparent, parent, and child posts (Make > Model > Version). On the single Version post page, I would like to display the Version information, as well as breadcrumb links to the single Model and single Make pages for its parent and grandparent posts. On the parent single Model page, I would like to show a View of all the Versions that belong to this parent. The breadcrumbs on this page should include a link to the grandparent Make post. On the single grandparent Make page, I would like to include a View that shows all the Version posts belonging to the grandparent Make.

Solution: Create a Content Template for Version posts. Include information about the Version by adding Field shortcodes. Create another View that will be used to display breadcrumb links. Add links to the parent and grandparent single post pages. Place this View in your Content Template.

Use a post relationship filter to create a View of Version posts. Filter to show posts that are children of the current post. In the Loop Output section, include links to each Version single post page. Create another View that shows links to the grandparent Make single post. Use this View to display breadcrumbs. Place both these Views in your Content Template for Model single posts.

Repeat this process for the grandparent Make Content Template, but remove the filter and update the breadcrumb structure to match your hierarchy.

Relevant Documentation: https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

This support ticket is created 7 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by Bochnacki 7 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#559387

I have a relation of posts: Make -> Model -> Version. These are CPT.
I have also created views for "make", "model" and "version".

The problem is that I do not know how to create link/relation to individual views based on saved post.
For example: I have post "Audi A4 B8" where "Audi" is the make, "A4" is the model, "B8" is the version. How to create in the post view "Audi A4 B8" links to:
view "brand" where will only "Audi"
view "model" where there will only be "A4"
view "version" where will only "B8"
The same principle should work links in the post eg "BMW Serie5 E60" or "Mercedes ClassE W210",...

I will be grateful for the help or suggestions.

#559532

Hi, we have a couple of guides you can use to access information about parent, grandparent, and other ancestor posts:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

To link to a parent, you can use the "id" attribute in a wpv-post-link shortcode:

[wpv-post-link id="$model-type-slug"]

For grandparents, grand-grandparents, and so on, you must create Content Templates that can be used to access ancestor information. Let me know if you have additional questions about this.

#560480

Sorry for the delay with the response.
Links seem to work well. But I can not set views. I'm working on it.

And in connection with the topic of https://toolset.com/forums/topic/ctp-relationships-in-dropdowns/ can any additional problems occur?

#560495

And in connection with the topic...can any additional problems occur?
If a post has no parent, and you try to access its parent in a shortcode, you will see information from the current post instead. For example, let's say you add some code to Post 1. This post does not have a parent post. Let's say you include this code in Post 1:

[wpv-post-link id="$parent"]

When you look at Post 1 on the frontend, you will see the link to the child post, Post 1. If you want to hide this link instead of showing the child post link, you must use conditional code that tests the ID of the current post against the ID of the parent post. If they are the same, this post has no parent. If they are different, this post has a parent.

[wpv-conditional if="( '[wpv-post-id]' eq '[wpv-post-id id='$parent']' )"]
    this post has no parent, so do not display the link
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-id]' ne '[wpv-post-id id='$parent']' )"]
    this post has a parent, so display the link: [wpv-post-link]
[/wpv-conditional]

It's something that confuses many people, because they think that if the $parent does not exist, the link will not be shown. This is not the case. You must use conditional code.

#560697

I can not handle the parent display correctly in "make", "model", and "version" views. Please, you can take a look at what I'm doing wrong.
hidden link - make
hidden link - model
hidden link - version

And I have more and more concerns as to how it will work in the context of the https://toolset.com/forums/topic/ctp-relationships-in-dropdowns/

#560877

I started in the Wersja View, and noticed that it was displaying incorrectly. I'm not sure why, but I was able to edit the Content Selection and save it, then restore it to Osobowe, and now it is showing the proper posts.

Wersja View here:
hidden link

See the View displayed here:
hidden link

I see one problem I would like to mention in all 3 Views. See this code:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
<div class="offers-tools">
    <h1>Pojazdy osobowe - [wpv-post-title]</h1>

In this case, wpv-post-title does not show the title of the Osobowe post, it displays the title of the current post. In the case of the test page above, the current post title is the page, and the page title is "Test". So I don't think you will see the expected post title this way. To show the title of the post in the Loop, you must move the wpv-post-title shortcode into the Loop, between the wpv-loop tags.

And I have more and more concerns as to how it will work in the context of the https://toolset.com/forums/topic/ctp-relationships-in-dropdowns .
I would like to help address these concerns, but I would also like to keep this ticket focused on the link issue. Please open separate tickets so we can address these concerns while keeping the forum organized. Thank you for understanding.

#561499
make-model-version.jpg

I have the impression that we do not understand.
I want to see the posts same as the "Person", not the list of posts of posts.
Please visit screen "make-model-version.jpg".

#561687
post-body.png
query-filter.png
error.png

Thank you.

1. See error.png. I fixed an error message in your View here:
hidden link
/auto-box/osobowe-marka/audi/

The ancestors argument does not end with a valid parent for the returned post types on this View.

It appeared to be related to this filter:

[wpv-control-post-ancestor type="select" default_label="Wersja" format="%%NAME%% <span>(%%COUNT%%)</span>" ancestor_type="osobowe-wersja"]

Post type "Osobowe" does not have a parent post type called Osobowe Wersja, so this filter was failing. I have updated this filter to remove the Wersja parent, and the error is no longer displayed. Please apply the same changes to your other Views if needed.

2. See query-filter.png. I believe the Query Filter for this View was incorrect:
hidden link
I believe the Query Filter should be set to "Select posts that are children of... Post where this View is shown", because you want to show Osobowe posts that are children of the "Audi" Osobowe Marka, correct? I have made this change, but you should probably apply similar changes to your other Views as needed.

3. The post body shortcode was pointing at the "make" instead of the Osobowe. See post-body.png. This is not correct:

[wpv-post-body id="$osobowe-marke" view_template="Loop item in Ogloszenia - osobowe"]

You should not use the ID attribute here to point at the Make. The View finds Osobowe, and you want to display information about the Osobowe. I have made this change here, but you will probably need to apply similar changes to your other Views.

Please apply changes as needed to your other Views, and let me know the results.

#561924

It works great!
Thank you so much for your help and clarification.