Skip Navigation

[Resolved] Create a slider that shows other posts from the same parent

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

Problem: I have a one-to-many relationship set up between two post types. In the child post single page, I would like to display a View of other sibling child posts.

Solution: This feature does not currently exist in Blocks, but in classic Views you can create a Query Filter for post relationship, where the parent post is set by a shortcode attribute "wpvrelatedto". Then you can provide the current post's parent post ID in the View shortcode as shown here:

[wpv-view name="your-child-view-slug" wpvrelatedto="[wpv-post-id item='@relationship-slug.parent']"]

Relevant Documentation: https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/

This support ticket is created 3 years, 8 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
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 2 replies, has 2 voices.

Last updated by Marcel 3 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1729489

I created 2 custom post types; artists and artworks. I set a one to many relationship with the artist as the parent and the artwork as the children, since 1 artist has multiple artworks.

On the single artwork template, I want to show a slider with the other artworks of that artist. I have the slider working, but it shows all artworks, from all artists. It should only show artworks by the same artist (so the children (artworks) of that parent (artist).

I have tried to set a filter, but I get either all artworks from all artists, or only the current artwork I'm viewing. Which filter settings do I need to get this right?

#1729847
Screen Shot 2020-08-06 at 2.17.49 PM.png

Hello, you need a way to filter a View of child posts by the parent of the current page. There's not currently a way to achieve this in Views built in the Block Editor, but we're working to improve that feature in upcoming releases. In classic Views, you can achieve this with a post relationship filter, where the parent post is set by a shortcode attribute like wpvrelatedto. See the screenshot here for an example. Be sure the checkbox for "Don't include the current page in the query result" is checked so the current post will not appear in the View results.

When you place the View in your single Artwork template using a shortcode, you can supply the current post's parent ID in the wpvrelatedto attribute using the wpv-post-id shortcode, the item attribute, and the relationship slug syntax, like this:

[wpv-view name="your-child-view-slug" wpvrelatedto="[wpv-post-id item='@relationship-slug.parent']"]

Replace your-child-view-slug with the slug or name of your View, and replace relationship-slug with the slug of your Artist - Artwork post relationship. You can find the slug in Toolset > Relationships when you edit the post relationship.

Let me know if you have questions about this approach.

#1730691

My issue is resolved now. Thank you!

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