Skip Navigation

[Resolved] How do I extract json for a view? Or how do I extract json for relationsships?

This support ticket is created 2 years, 5 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/Karachi (GMT+05:00)

Author
Posts
#2204095

Hi,

I have created two post types "Tours" and "Pois" and added a many-two-many relationship between them. At the moment I have one "tour" that has relationships to several "pois".

I want to extract JSON for the "tour" *and* the "pois" that are related to the "tour".

I am able to extract the json for the "tour", but it doesn't show the relationships. I am using Javascript and the "fetch" function.

The json I get looks as follows, which is fine, but the relationships are not there:

{"id":117,"date":"2021-10-24T12:55:34","date_gmt":"2021-10-24T12:55:34","guid":{"rendered":"hidden link"},"modified":"2021-10-24T13:29:55","modified_gmt":"2021-10-24T13:29:55","slug":"test","status":"publish","type":"view","link":"hidden link","title":{"rendered":"Test"},"content":{"rendered":"","protected":false},"author":1,"template":"","_links":{"self":[{"href":"hidden link"}],"collection":[{"href":"hidden link"}],"about":[{"href":"hidden link"}],"author":[{"embeddable":true,"href":"hidden link"}],"wp:attachment":[{"href":"hidden link"}],"curies":[{"name":"wp","href":"hidden link{rel}","templated":true}]}}

----
I have also created a view trying to extract the json for the "pois" that are part of that view. I am able to extract the json for the view itself, but not for the contained "pois". It looks as follows

{"id":64,"date":"2021-10-21T20:12:04","date_gmt":"2021-10-21T20:12:04","guid":{"rendered":"hidden link"},"modified":"2021-10-21T20:12:05","modified_gmt":"2021-10-21T20:12:05","slug":"stockholms-sevardheter","status":"publish","type":"tour","link":"hidden link","title":{"rendered":"Stockholms sevärdheter"},"content":{"rendered":"This tour takes you...","protected":false},"template":"","_links":{"self":[{"href":"hidden link"}],"collection":[{"href":"hidden link"}],"about":[{"href":"hidden link"}],"wp:attachment":[{"href":"hidden link"}],"curies":[{"name":"wp","href":"hidden link{rel}","templated":true}]}}

Please advice.

Thanks,
Håkan

#2205029

Waqar
Supporter

Languages: English (English )

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

Hi Håkan,

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

From your message, it is not clear exactly how you're extracting the JSON from the posts.

To get the related posts, you can use the "toolset_get_related_posts" function, in your PHP code:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

If you could share more specific information about your workflow and the requirement, I'll be in a better position to assist you accordingly.

regards,
Waqar

#2207693

I found a solution.

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