Skip Navigation

[Resolved] Connecting Two Tables with Relationships dynamcially

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/Karachi (GMT+05:00)

Author
Posts
#2583745

Tell us what you are trying to do?
List all resources (Resources) that have a relationship to a second table (the originating Organizations).

E.g., I have parent company that has several resources (documents, website etc.). The parent company is in a Field Type called 'Organizations' while the resources are in a Field Type 'Resources'. When a user clicks 'Read more...' from the Organization Archive page, they are taken to another page (I'm not sure which template this is drawn from, the Organization Single or the Organization Archive).

In any case it appears that I must manually visit every Organization and manually connect each resource to it in the 'Organizations Resources' section at the bottom of every Organization listing page in the WordPress admin area.

Is there any way to dynamically connect the two so I don't have to manually connect all the resources to the Organization page? E.g., I have an 'org_id' code I manually created and put that number in an 'org_id' column in the Resources data for all of the Resources for that org.

Is there any documentation that you are following?
Relationships Lessons

Is there a similar example that we can see?
If you click on the Council of State Governments organization page you will see what I got so far. I have also had the hardest time trying to understand which template or archive page I should be editing to enhance this page. E.g. I want to include the Type, Title, and Categories, of each Resource.

What is the link to your site?
hidden link

Thanks for any help!

#2584243

Hi,

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

You can choose to store the individual 'organization' post's unique 'org_id' in the related 'resources' posts, custom field value, to form a link between them. However, this will work as an alternative to the post-relationship feature and won't connect these posts in the relationship, automatically.

Toolset does offer a function 'toolset_connect_posts' to programmatically connect two posts in a relationship.
( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts )

It can be used in a custom function attached to the 'save_post' hook that fires each time a 'resource' post is created or updated to form a relationship with the 'organization' post whose 'org_id' is stored in the custom field.
( ref: https://developer.wordpress.org/reference/hooks/save_post/ )

But customization like this can be challenging to deploy and maintain in the long run and can result in data inconsistency issues.

As for customizing the 'Organization' archive page ( {yourwebsite.com}/orgs/ ), please go to WP Admin -> Toolset -> WordPress Archives and you'll find the archive assigned to this post-type archive page.

I hope this helps and please let me know if you need further assistance.

regards,
Waqar