Navigation überspringen

[Gelöst] Access associations via API

This support ticket is created vor 5 Jahren. 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/Karachi (GMT+05:00)

Dieses Thema enthält 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Waqar vor 5 Jahren.

Assistiert von: Waqar.

Author
Artikel
#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

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