Skip Navigation

[Resuelto] Create a View that shows sibling child CPT posts on the single CPT page

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I would like to create a View that shows siblings of the current Post

Solution:
Create a View to search for your child CPT posts. Configure the Query Filter to filter by Post Relationship. Set up the filter to respond to a shortcode attribute "wpvprchildof".

In Query Options, check "Don't include current page in query result" so that only sibling posts will show up, and the current post will not be shown.

In the Loop Output editor, use the Fields and Views button to include a link or other information about each sibling.

Add the View from step 1 into the Content Template for your CPT single post page using this shortcode:

[wpv-view name="playlist" wpvprchildof="[wpv-post-id id='$serie']"]

You can see the wpvprchildof attribute required by the filter from step 1. The value of this shortcode attribute will provide the post ID of the parent post:

[wpv-post-id id='$serie']

Relevant Documentation:
https://toolset.com/documentation/user-guides/displaying-brother-pages
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
https://toolset.com/documentation/user-guides/filtering-views-query-by-post-parent/

This support ticket is created hace 6 años, 6 meses. 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)

Etiquetado: ,

This topic contains 14 respuestas, has 2 mensajes.

Last updated by thomasS-11 hace 6 años, 6 meses.

Assisted by: Christian Cox.

Autor
Mensajes
#578122

I have 2 post types, Videoseries (playlists), and Videos. Videos are children of Videoseries.
When viewing a Video post, i am trying to display the videos in the same videoserie as current one.
I tried following this tutorial: https://toolset.com/documentation/user-guides/displaying-brother-pages - no luck there.

Further more, it seems that your View filter is only looking for WordPress hierarchicals when using the "Post is parent of" filter. So when ever i tried the solution in above link, i kept getting this message: "This will filter out posts of the following types, because they are not hierarchical: Videoer".

#578239
Screen Shot 2017-10-12 at 10.36.40 AM.png

Hi, it sounds like you're describing the difference between the Post Parent filter and the Post Relationship filter. See the attached screenshot of filter options for a visual here. "Post Relationship - post is a child of" is the filter you should choose if you're interested in displaying parent / child relationships between different post types. "Post Parent" is used for WP hierarchical post types.

Is there a specific part of the tutorial that you're getting stuck on? If you edit your Query Filter to use Post Relationship instead of Post Parent, are the results more like you expect? If not, please let me know where I can offer guidance and I'll take a closer look.

#578243

Hi Christian

This wont solve the issue. I should have made my self more clear. The problem is not the filter - the approach/solution it self dont work. Even if i use "Child is a post of" - i get the message: "This will filter out posts of the following types, because they are not hierarchical: Videoer".

My point with this is, that appearantly it does not consider post type to post type as hierichal.

Also, the videos im trying to show is not a child of the current post- but of the current post's parent - hence, siblings and not children. The view im trying to design here, is going to a Video post, not Video serie. Which is why i doubt this alone will work.

In the end of the provided tutorial, you describe yourself that this is done with WordPress-hierachy and now post type hierachi, linking to the page called something about "grand-parents" - in the summary on the bottom of the page.

#578254

Also, the videos im trying to show is not a child of the current post- but of the current post's parent - hence, siblings and not children.
Okay let me try to clarify. In steps 1 and 2 you create a Content Template, which shows the parent of the current Video, which is the Videoseries. Inside this Content Template, you will place a new View. This View's query filter context is the parent Videoseries. So you filter by children of the current Videoseries, not by children of the current Video. The key here is context, and understanding that the Video View is placed in the context of a parent Videoseries. If you placed this View directly on the Video page, then it would not work because the current post is a Video, and Videos are not children of other Videos. It works because you place the View in the context of its parent Videoseries by using a Content Template and the id="$parent" attribute.

Even if i use "Child is a post of" - i get the message: "This will filter out posts of the following types, because they are not hierarchical: Videoer".
Can you please attach a screenshot showing the problem you are describing? I would like to review the settings of your View's query filters so I have a better understanding of what's occurring.

#578255

My apologies, I chose the wrong setting for my last reply. Please let me know your responses to my last comment and we can continue from there. Thanks!

#579008

I will try this and get back to you. Thank you

#579137

Sure, let me know when you're ready to continue.

#580786
Udklip.PNG

I really cannot get this thing to work. It's becoming very frustrating at this level. I used Views for so many big and advanced tasks, but i simply cannot get this simple thing to work.

What i am trying to achieve, is a simple unordered list, displaying Fields from sibling posts. I dont understand the 2 content templates, and where to use them.
I simply want a view, that i can insert in the post template with PHP.

You asked for a screenshot of the issue i get with parents, and i have attached it to this reply.

Can you please step by step explain to me, how i create a View that i can insert in my single-video.php template that shows the sibling posts of curent?

#580789

Even if i was to make this succeed - how do i insert the Content Template in my PHP template file? i am so confused right now.

#580883

Hi, sorry this is causing you so much grief. If you agree, I would like to log in to your wp-admin area so I can set this up for you, then we can walk through it together and hopefully it will become clearer. If that's okay with you, please provide login credentials in the private reply fields I have enabled here.

#581008

I dont know why the FTP path above is set to initial.
When entering the FTP credentials, you will land in the installation root.

#581226

Okay let's take a look. I have set some things up that I would like to describe.
1. Look at the View here:
/wp-admin/admin.php?page=views-editor&view_id=68
I have configured the Content Selection area to search for "Videoer" posts, because you want to list "Videoer" posts. Initially it was set to show Videoserie posts as well, but you don't need that in this case.

I have also configured the Query Filter to filter by Post Relationship. The filter is set up to respond to a shortcode attribute "wpvprchildof". I did this so we can filter by parent Videoserie, and we want to be able to use the same View in all Videoer posts. These posts can have different parent Videoserie, so we need this to be dynamic.

In Query Options, I have checked "Don't include current page in query result" so that only sibling posts will show up, and the current post will not be shown.

In the Loop Output editor, I have simply placed the title of the Videoer post using the shortcode wpv-post-title. You can modify the output here if you'd like to show a link, or other information about each sibling.

2. Look at the Content Template here:
/wp-admin/admin.php?page=ct-editor&ct_id=160
This is the content template applied to the bottom of the single Videoer post. I have added the View from step 1 into the Content Template using this shortcode:

[wpv-view name="playlist" wpvprchildof="[wpv-post-id id='$serie']"]

You can see the wpvprchildof attribute required by our filter from step 1. For the value of this attribute, I have included another shortcode that will provide the post ID of the parent Vidoeserie post:

[wpv-post-id id='$serie']

So now this View will work on any Videoer post, because it will dynamically determine the parent Videoserie, then show only sibling posts of the current post.

Let me know if I have misunderstood what you're trying to accomplish and I will take a closer look.

#581564

Hi Christian

Thank you for your assistance. It seems to work as intentional now.

May i suggest you make a tutorial for this, on your website? - Im pretty sure 99% will fail on this task, if they did not do it before, since there is no explaination for the attribute "wpvprchildof".

Further more the "post is child of" isnt working the intentional way - so you had to use the shortcode attribute in the filters. Im kind of confused in why the "post child/parent" filter is not working with "post type to post type" relations. I remember this is as the actual thing this filter was created for?

Thank you for explaining the issue instead of simply fixing it - this helps me do the task myself in the future without asking for support again 🙂

#581597

Ok great, glad it's working as expected.

May i suggest you make a tutorial for this, on your website? - Im pretty sure 99% will fail on this task, if they did not do it before, since there is no explaination for the attribute "wpvprchildof".
There's a related document about passing arguments to Views here:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
It describes a few different methods for making filters dynamic (i.e. respond to variable conditions), and shortcode attributes are one example of those methods.

Im kind of confused in why the "post child/parent" filter is not working with "post type to post type" relations. I remember this is as the actual thing this filter was created for?
The post parent filter is for parent/child relationships in one hierarchical post type, like the relationships between native WordPress "Pages". The post relationshipfilter is for relationships between parents and children across different post types. More information about post parent filters can be found here:
https://toolset.com/documentation/user-guides/filtering-views-query-by-post-parent/

Further more the "post is child of" isnt working the intentional way - so you had to use the shortcode attribute in the filters
Since a single post can have a parent in more than one other post type, we need to know which parent post type should be used in this filter. That's one reason I have chosen to use a shortcode attribute. It will respond to the context of the current Videoer post and provide the proper Videoserie parent post, because that's what we told it to do in the shortcode. This makes the View more flexible, and you have the ability to reuse it in multiple contexts. For example, if you create a new post type called Video Collection which is also a parent of Videoer, then you could reuse the same View and pass in a different shortcode attribute to show sibling Videoers in the same Video Collection:

[wpv-view name="your-view-slug" wpvprchildof="$video-collection"]

Feel free to create tickets whenever you feel like you're getting stuck, and we'll try to get you back on track.

#581965

You may ignore this reply 🙂 Once again thank you for your support!

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