Skip Navigation

[Resolved] Question about post relationships

This support ticket is created 5 years 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Jackie 5 years ago.

Assisted by: Christian Cox.

Author
Posts
#1219697

Hi there,

Let's say that I have two posts that are connected to each other via a parent-child relationship. Is it possible to require the parent post to be connected to a child? This is similar to a required custom field, but this would be a required *relationship*. Does that make sense?

The reason I'm asking is that I have a design that requires posts to be connected to other posts, otherwise the correct information won't appear on the website and error messages _will_ appear.

Thanks!

Saul

#1220059

Hi, there's nothing built-in to require at least one relationship connection. We do offer the post relationships API, which can be used to query for related posts in a specific post relationship. I could show you how to write a custom function you can use in a simple conditional to test whether or not a specific post has any child posts. Let me know if you think a conditional-based approach will work.

#1220557

Nah, I don't think I need the starter code.

I ended up attaching a function to the filter "edit_form_top" and checking the results of the post count returned by toolset_get_related_posts() or toolset_get_related_post() and printing warnings where appropriate. It still doesn't force the user to create the necessary post relationships, but it at least informs the user there will be a problem if they don't. That's good enough!

Thanks, Christian!

Saul

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