Skip Navigation

[Resolved] SQL Query to get content from 2 custom post type with a relationship.

This support ticket is created 3 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 3 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2276565
Relationship.JPG

I'd like to write a SQL query to extract content from 2 custom post types(Chapters and Members) that have a relationship

Chapters and Members
1 chapter can be assigned to one member
infinite members can be assigned to one chapter

I've looked at the various tables but I'm not able to determine which tables contain the relationship info to do the necessary Join in my SQL statement. Would you please provide some insight or additional documentation on how to accomplish my SQL Query

#2277363

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

We offer post relationship API function to get related posts:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

In addition to that if you want to use core WP_Query, please check the following Doc:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts

Please let me know if that helps.

#2277711

While this information is helpful, it doesn't solve my problem. do you have schema documentation on the database tables you are using for relationships? I'm not using php or your api, I'm writing SQL.

#2278347

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please check the following screenshot for schema: hidden link

The relationship with content is stored using the following database tables:
- {db-prefix}_toolset_connected_elements
- {db-prefix}_toolset_relationships
- {db-prefix}_toolset_associations
- {db-prefix}_toolset_type_sets
- {db-prefix}_posts

I hope this helps.