Skip Navigation

[Resolved] Legacy Views Queries with Repeatable Field Groups

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 2 months, 3 weeks ago.

Assisted by: Waqar.

Author
Posts
#2680635

Tell us what you are trying to do?
I have a site with Restaurants (displaying on post-type POSTS) and a custom post-type WINES that I have associated with POSTS with a many-to-many RELATIONSHIP.
WINES that are offered for sale by the RESTAURANT are selected for that RELATIONSHIP field.
Each RESTAURANT offers the associated WINE at a different PRICE.
I want to display in a GRID on a RESTAURANT ("post") those WINES that are associated with that RESTAURANT ("post").
I have created a LEGACY VIEW that flawlessly displays the associated WINES on the RESTAURANT post displaying the featured image, custom fields and taxonomies for the WINES.
I am attempting, however, to include the PRICE at which each of those WINES is sold in each of the table grid cells.
I have not previously used REPEATING FIELD GROUPS and thought this might be the required solution.
What is the best solution for getting the price of each wine that is uniquely connected to the RESTAURANT ("post") displayed on the POST in that TABLE GRID that includes the items (image, custom fields and taxonomy terms) from the WINES cpt?
Thanks.

#2680728

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

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

Whenever two post types are joined through a many-to-many relationship, an intermediary post type is also created. Whenever two posts are connected through that relationship, a new post entry is added to that intermediary post type.
( ref: https://toolset.com/course-lesson/many-to-many-post-relationships/ )

The 'Price' in this case needs to be different for each connection between a wine and a restaurant. It will not be generalized for either a wine or a restaurant. For this reason, it will need to be saved with each connection through the relevant intermediary post entry.

You can add custom fields to an existing many-to-many relationship, by going to its edit screen at WP Admin -> Toolset -> Relationships.
( The 'Add Fields' button will be at the bottom, on the individual relationship edit page )

Note: On the individual wine or restaurant post pages, you can add a view that shows the related intermediary posts and any custom field data associated with them.

regards,
Waqar

#2681724

I have created a Wine Price custom field in the Intermediary Posts (Restaurant) - Wine post-type. And have entered data for the each of fields for the related items. I am not clear on how to display that field.
I want to display the data in a Restaurant (Post) using a legacy view in a table format that will eventually include the intermediary Price Field and several custom fields and taxonomy terms from each Wine related to that Restaurant (Post).
Do I query both the Wine and the Intermediary custom post types in a single loop / view or do I have to use a nested loop? Please provide details on how to set up the legacy view or views. Thanks.

#2681953

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

The steps that you've taken to add the price field to the intermediary post type are correct.

> Do I query both the Wine and the Intermediary custom post types in a single loop / view

- The view that you will show on the single wine or restaurant page, only needs to select the intermediary post type. In the query filter section, you'll include a post-relationship filter to show only the related posts for the current post.

In the loop of this intermediary posts view you'll have the ability to show the custom field, taxonomy, and post data from the related wine and restaurant too, through the 'item' attribute:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

In the documentation of Toolset shortcodes for showing post data and Types fields API, you'll see that they all support the 'item' attribute:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#displaying-data-2
https://toolset.com/documentation/customizing-sites-using-php/functions/

For example, suppose you have a setup where 'wines' post type is the parent and the 'restaurants' post type is the child in a many-to-many relationship with slug 'wine-restaurant'.

Here is a simple example usage of the 'wpv-post-title' shortcode to show titles of different posts, in this view's loop:


// this will show the current intermediary post's title as no item attribute is specified
[wpv-post-title]

// this will show the parent wine post's title
[wpv-post-title item='@wine-restaurant.parent']

// this will show the child restaurant post's title
[wpv-post-title item='@wine-restaurant.child']

Using the same approach, you can show any data from the current intermediary post, related parent or related child posts, by using the relevant shortcode.

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