Skip Navigation

[Resolved] Post relationship and post

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

Problem:

Setup many-to-many relationship and display related posts.

Solution:

You can follow our document to setup the many-to-many relationships:

Relevant Documentation:

https://toolset.com/course-lesson/many-to-many-post-relationships/

This support ticket is created 2 years, 11 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
- 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/Hong_Kong (GMT+08:00)

This topic contains 14 replies, has 2 voices.

Last updated by alistairW-2 2 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2020117
IMG_989AECBBD06C-1.jpeg

Tell us what you are trying to do?
I am struggling with the setup of my data. I have a parent post type (FlyPatterns). These fly patterns are composed of a series of parts (head, tail, body etc) that in turn are made of materials stored elsewhere (materialist post type).

Any part can be made of any material.

I had defined the parts as custom fields in the parent post type but am now realizing I can not connect those CF to another post(table) to input/org the data.
I can easily make the parts child posts for each flypattern but how can I build a relationship to the materailist post type to populate the parts?

Sorry I am used to defining a database structure in MS project and I cant seem to replicate it in WP/Toolset.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2020237

Hello,

I assume we are talking about this case:
1) Two post types:
- FlyPatterns
- materialist
2) One "FlyPatterns" post can connect with multiple "materialist" posts
One "materialist" post can connect with multiple "FlyPatterns" posts

If it is, then you can try to setup many-to-many relationship between post types "FlyPatterns" and "materialist"

See our document:
https://toolset.com/course-lesson/many-to-many-post-relationships/

#2021367

Luo,

There would actually be a number of additional post types 'inbetween' FlyPatterns and Materialist that define what part of the fly each material is used to make like Body, Tail, wing. Each Body needs to contain all the materials from Materialist that make up that part for each fly. And it will be different for each flypattern.

I tried to do this today and i think it would work but to me it seems very extenisve. I have to have a PT for each part of the fly, then define a relationship for each of those 20-30 PT to the FlyPatterns PT. Then define a relationship between each part and the Materialist PT. I also realised that each item in the parts (body,tail, wing etc) have to be named and so I was naming them the same as the material being used which to me seems to replicate data? I'm looking for advice on how best to set this up with Post types, relationships, CF (but CF dont seem right) thanks

#2021695

I don't think you need 20-30 additional 'inbetween' post types, you just need to setup one many-to-many relationship between post types "FlyPatterns" and "Materialist" with one intermediary post type, for example "FlyPatterns-Materialist", in this intermediary post type, add a custom select(radio) field "fly-part", with options:
- Body
- Tail
- wing
..

So when you connect the "FlyPatterns" and "Materialist" posts, you can choose field "fly-part" easily, see the document I mentioned above:
https://toolset.com/course-lesson/many-to-many-post-relationships/

Screenshot:
https://toolset.com/wp-content/uploads/2020/08/add-relationship-fields.png

#2022507
Untitled.jpg

Hey Luo.
I tried what you suggested with the many to many relationship and using the intermediary post type. I thnk i have done this correctly ( i used a few parts to test) are there any limitations as to how i can present this intermediary data on a page/template?

Also should I consider putting these material types in a hierarchical taxonomy, but then how could I apply them to the parts of each fly pattern? Just considering options

thanks

#2022813

You can follow the document I mentioned above to display the related posts:
https://toolset.com/course-lesson/many-to-many-post-relationships/#displaying-related-posts
section "Displaying Related Posts"

But the intermediary post type does not support custom taxonomy.

#2022815
Untitled.jpg

Luo,

The set up you suggested does seem to be working and I can display a list of materials associated with each Flypattern by creating a view based on materialist and filtering by those that have a relationship with Flypatterns. What I can not seem to do is display the custom field name associated with each of those displayed items from materialist (which is the flypart).

I hope the image helps you to understand. I'm trying to get the items marked in red into the content template and all i can get is a 1/0 based on the check box? thanks

#2022931
relation-filter.JPG

I assume those custom fields you mentioned above are in intermediary post type.

If it is, please try these:
1) In the single "Flypattern" post, add a view block:
- Query intermediary post type posts
- Filter by the post type relationship between "FlyPatterns" and "Materialist"
See my screenshot relationship-filter.JPG
https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items
- In view's loop, display those custom fields you mentioned above, you can also display the related "Materialist" post information too:
See the above document:
https://toolset.com/course-lesson/displaying-related-posts/#displaying-one-related-item-parent
section "Displaying one related item (parent)"

#2023269
toolset1.jpg

Sorry Luo its still not working.

I did as you suggested and placed a view, filtering for all items in the relationship. I can select the Materialist post as source for a field and display all the materials related to the current flypattern (#1 in image).

However, I need the custom field NAME that each of those materials is associated with. When I add a field I do get the option to chose fields from Related: Fly Pattern and I chose the relevant CF but it is empty (#2 in Image). (when you go into the post type you can see the CF checkboxes are there but they have no value. The relationship table is there showing they are connected #2A) So I tried changing the source to current intermediary post and I then get the value 1 which I assume is because the checkbox is checked! (#3)

I dont want the value of the checkbox or even the value in the post. I want the NAME of the CF that the material is tied to as in the image from previous. I want it to say "CF Name= Materialist item it relates to". So Eyes = Krystal Flash etc.

To make it worse, I am trying to put this in a content template and when I add the same view (intermediary filtered) to a template (Indvfly) I dont even get the option to chose any related fields for the source. Even though the view is set to intermediary post I only see the flypattern as source? #4. But for now I would just likee to understand how to do this in a post, page or content template.

Thanks for your help

#2025685

Please provide a test site with the same problem, fill below private message box with the test site credentials, also point out the problem page URLs, I need to test and debug it in a live website, thanks

#2026911

I have tried the credentials you provided above, it is not valid, I get below error message:

Oops, that's not the right password. Please try again!

Please check it, make sure it is a valid admin account

#2027975

Thanks for the details, I have changed above post to private.

And have done below modifications in your website:
Edit the content template "IdvFly"
hidden link

Find and select view block "mats22", change the filter to:
Select posts in a FlyPatterns MaterialLists relationship that are a related to the current post in the loop.

Add those three checkbox fields into view's loop

Edit the problem post:
hidden link
Connect with another "MaterialLists" post, it works fine in front-end:
hidden link

Please test again, check if it is fixed, thanks

#2028645
Untitled 7.jpg

Luo,

Thanks but this is still not working. In the page hidden link i want to see the name of the part AND the material. right now it is just showing the value of the check box. See image. Or maybe it is something I am doing in terms of displaying the site?

#2029269
single-field.JPG

I have done below modifications in your website again:
Edit the content template "IdvFly"
hidden link
1) Change it to related post title shortcode:
[wpv-post-title item="@flypattern-materiallist.child"]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-title

2) Change those three single checkbox field block, enable option "Custom values for selected and not selected states", setup the values in option "Custom values When selected", see my screenshot: single-field.JPG

#2031991

My issue is resolved now. Thank you!

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