Skip Navigation

[Resolved] Pass postID from one view to another view

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

Problem: I would like to pass values from one View into another View nested inside the original View.

Solution: You can place a View in a custom HTML block and include various shortcode attributes:

[wpv-view name="slug-of-nested-view" attr1="[wpv-post-id]" attr2="[types field='some-slug'][/types]"]

That would display the nested View and pass the current post ID from View 1 into an attribute attr1, and it would pass the value of custom field some-slug from the current post of View 1 into an attribute attr2.

Then in View #2, you can set various Query Filters to respond to these shortcode attributes, or you can use the wpv-attribute shortcode to access those attributes in the Loop editor:

Parent post ID: [wpv-attribute name="attr1"]<br />
Parent post custom field "some-slug": [wpv-attribute name="attr2"]

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-view
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-attribute
https://toolset.com/course-lesson/passing-arguments-to-views/

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

Last updated by jesperA-2 3 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#2134577

Hi,
I've finally moved to Toolset Blocks and loves it so far.
However, I got stuck on something that shouldn't be that difficult really:

What I try to do is to list Articles (custom post type). Each article have a Price (which is another custom post type) which should be editable in the View of articles. Both Article and Price have a relationship to Quote (custom post type) which is what connects them.
So a customer should be able to quickly set a Price for an Article connected to Quote.

I've created a view (#1) filtered by an URL param (Quote ID). Inside the view loop there's a content template containing another view (#2) of the price. This view contain a Price form and is also filtered by the URL param (Quote ID).
This works fine but for every article in the view (#1) I get a list of all prices (obviously) for this Quote.

So I added ArticleID as a field of the Price post type to connect the price to the correct article. What I now need is a way to filter the view (#2) inside the Content Template on the current article ID. However - I can't find a way to get the postID of the current Article in the view (#1) loop.

There must be a way to pass the current postID (articleID) of View #1 into the Content Template and then to View #2?
Or a way for the view #2 to get the postID of the outer view #1?

Ive search forums but can't find an example of how to solve this.

#2135093

Hello, the best way to pass arguments into a nested View is to place the nested View in the loop of the outer View using a wpv-view shortcode, rather than using a Content Template block with a View block inside it. You can place a View in a custom HTML block and include various shortcode attributes:

[wpv-view name="slug-of-nested-view" attr1="[wpv-post-id]" attr2="[types field='some-slug'][/types]"]

That would display the nested View and pass the current post ID from View 1 into an attribute attr1, and it would pass the value of custom field some-slug from the current post of View 1 into an attribute attr2.

Then in View #2, you can set various Query Filters to respond to these shortcode attributes, or you can use the wpv-attribute shortcode to access those attributes in the Loop editor:

Parent post ID: [wpv-attribute name="attr1"]<br />
Parent post custom field "some-slug": [wpv-attribute name="attr2"]<br />

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-view
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-attribute
https://toolset.com/course-lesson/passing-arguments-to-views/

#2135125

Yes, that's exactly what I was looking for (and it worked)!
A bit strange I didn't find this solution anywhere but maybe I complicated things a bit.
Anyway, thanks for the fast support Christian!

#2135127

My issue is resolved now. Thank you!