Skip Navigation

[Resolved] a view to show one-to-many relationship entries on any page

This support ticket is created 6 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 6 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#781524

I am trying to:

Thanks for creating relationship. I am testing for a network of tourist guides sites of small destinations in Chile and I find myself with some doubts.

I have ordered with custom post types:

Activities
Attractions
Accommodations
Gastronomy
Locations

Create a relationship of one is to many. For example, a locality has many attractions.
Now I have created a shortcode in a view that filters the attractions in a specific locality and that shortcode inserts it in a new page created by myweb.com/atractivesofthelocality. Until here everything perfect.

I expected to see:

The problem exists when I want to do this on a large scale, according to this example, I have to create one by one the views to show on a page attractive in a locality, or activities in a locality or etc, in a site that has more than 100 locations its a big problem.

Is there any way to create 1 single view for example of attractions in the locality, and in the shortcode or other place to be able to change what custom post types should show ?. Or can I create an attractive view, but in the shortcode can I change which location I want to show the entries?

So far I have only encountered examples of displaying custom post types entries depending on where the shortcode is located. For example insert the shorcode in the entrance of the locality filtering the view so that it shows the results according to where this insert.

I hope you have understood me.

From already thank you very much

Sorry for my English

regards

#783501

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Let me clarify one thing about Views, which is that the post type is set when you create the View and cannot be modified (unless you write some code using the API to modify the query).

You can pass arguments to Views to provide values for the filters, either by shortcode attribute (you add an extra attribute to the wpv-view shortcode where the View is inserted) or by URL parameter.

You can read more about this here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

Note, from your debug info it looks like you are using Layouts. You cannot use shortcode arguments if you are not using a shortcode to insert a View, which means if you are adding a View to a Template Layout you must insert the View using a shortcode into a Visual Editor cell, and not use a View cell.

For a situation where you have a location connected to multiple attractions, you would typically create a View to show attractions and include a relationship filter to show only attractions connected to the current location, with this View inserted into a template for locations, so that whatever location post you viewed on the front-end it would show the attractions connected to that location.

But if you want to display such a View on a different page that is not the location post you can pass the id of the location you want to refer to as a shortcode attribute. In your View add a filter for the relationship and specify that the location comes from a shortcode attribute. It will suggest a name for the attribute (which you can change) and then add this attribute when you insert the View with the wpv-view shortcode.

If you have problems implementing it let me know.