Skip Navigation

[Resolved] Access associations via API

This support ticket is created 4 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.

Our next available supporter will start replying to tickets in about 0.02 hours from now. 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 1 reply, has 2 voices.

Last updated by Waqar 4 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1406101

I need a copy of the associations between posts in another app. Is there a way to directly retrieve all associations between posts via API (e.g. toolset_get_associations) instead of querying the related posts of a specific post (toolset_get_related_posts)?
If not what way would you suggest to sync the associations?
Thanks for your help!

#1406723

Waqar
Supporter

Languages: English (English )

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

Hi Jonathan,

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

I'm afraid, there is no single function available to get the information about all existing post associations, but as you noted, "toolset_get_related_posts" function can be used to get them on a per-post basis.
( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts )

There are a couple of ways you can approach this, based on the overall structure and requirement of your app:

1. You can create a custom function to run periodically (using Cron) that loops through one of the post types in the relationship and fetch the attached posts to them and update the existing records to keep the data in sync.

OR

2. You can use "toolset_association_created" hook ( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created ) to attach a custom function that can send the information to your external app that a new post association has been created.

Likewise "toolset_before_association_delete" hook ( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_before_association_delete ) can be used to attach a custom function that can send the information to your external app that an existing post association is going to be deleted.

I hope this helps.

regard,
Waqar

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