Skip Navigation

[Résolu] Show Related child posts

This support ticket is created Il y a 5 années. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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

Supporter timezone: Asia/Karachi (GMT+05:00)

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Waqar Il y a 5 années.

Assisté par: Waqar.

Auteur
Publications
#1396867
Screen_Shot_2019-11-30_at_1_05_03_PM.png

I have a cpt called Special Reports and another CPT called special article.
I have a one to many relationship betweeen Special Reports and special article, whereby one special report can have unlimited special articles:

-Special Report
-- Special Article

I am trying to create a view where on the single special article, it shows all the special articles that are related to the parent special report ( so that on the side of a single special article I can show all the other special articles belonging to the same special report)
So far all the filtering options render "No results found"

#1397213

Hi Adrian,

Thank you for contacting us and I'd be happy to assist.

To achieve this, you can follow these steps:

1. First, you'll need the ID of the "Special Report" post that is attached to the current "Special Article" post.

You can use "wpv-post-id" shortcode ( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-id ) with "item" attribute ( ref: https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/ ), like this:


[wpv-post-id item="@{relationship-slug}.parent"]

Note: you'll replace "{relationship-slug}" with the actual slug of this relationship.

2. Next, you'll need a post view to show the "Special Article" posts, but it will have a query filter that will make it bring only those posts which are related to the "Special Report" post, whose ID is passed in the view's shortcode attribute, similar to what is shown in your screenshot.
( ref: https://toolset.com/documentation/user-guides/passing-arguments-to-views/ )

On your single post pages for special articles, you can call this new view like this:


[wpv-view name="slug-of-the-view" wpvrelatedto="[wpv-post-id item='@{relationship-slug}.parent']"]

Note: replace "slug-of-the-view" with the actual slug of your view.

You can check the option "Don't include current page in query result" in the view's "Query Options", to make sure that the current special articles post is not included in the results.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar