Skip Navigation

[Resolved] How to get all the ID's of linked posts using a [wpv-post-id] shortcode

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

Last updated by igorL-3 3 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#2223301

Tell us what you are trying to do? I have a many to many relationship. In this particular case I have one post which is linked to many other posts. I want to get an indexed list/array of all the linked posts. When there is only one linked post I have used the shortcode [wpv-post-id item='@slug.parent'] this works fine. When I use the same shortcode for the above case it only gives me the first linked post. How can I get the other linked posts using this shortcode?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2223459

Shane
Supporter

Languages: English (English )

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

Hi Igor,

Thank you for getting touch.

When using a many to many relationship and you want to get the ID of the parent you will need to use a view to get all the posts of the Parent.

From there you can display the ids using the [wpv-post-id] shortcode.

Essentially what you're going to do is go to Toolset->Views and add a new view. Then select the Parent Post type.

Under the query filter section you will add the query filter for Post Relationship and set it to filter based on the post where the view is added.

From there you can populate the view using the Loop Wizard to add the post ID.

Finally just add your view to the content template that you're using to display the child post.

Please let me know if this helps.
Thanks,
Shane

#2223473

Yes thank you, I can do that but then I need to be able to address them individually by some index. For examle say all the ID are in array called $posts. I then need to address each one $posts[0], $posts[1], $posts[2], ...

#2224135

Shane
Supporter

Languages: English (English )

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

Hi Igor,

The only other way to do this is by crafting some custom code using the hook below
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

Using this hook will allow you to return an array of posts in the relationship whether it be the parent or child. Crafting this into a custom shortcode will also allow you to pass various parameters into the hook that you can use to pick off individual IDs if needed.

One of the Tools that can be used to generate the framework of your shortcode is.
hidden link

Please let me know if this helps.
Thanks,
Shane

#2224137

Shane
Supporter

Languages: English (English )

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

Hi Igor,

The only other way to do this is by crafting some custom code using the hook below
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

Using this hook will allow you to return an array of posts in the relationship whether it be the parent or child. Crafting this into a custom shortcode will also allow you to pass various parameters into the hook that you can use to pick off individual IDs if needed.

One of the Tools that can be used to generate the framework of your shortcode is.
hidden link

Please let me know if this helps.
Thanks,
Shane

#2224261

My issue is resolved now. Thank you!