Support

Account

Home Forums General Issues Nested Relationship Backward query

Solving

Nested Relationship Backward query

  • Hey team,

    I am trying to work out how to do this query. Before I start here is what I currently have:

    Custom Post Type: Cast Members (Only contains a title, description and feature image)

    Post Type: Events – I have added a custom field group ‘Production’ which has a repeater field ‘characters’ within the characters field there are two fields – character(Text) and cast_member(Relationship) that links to the Cast Members Post Type.

    I have successfully created a list of cast members in the individual events page when you click on the cast members name it then links to a single page displaying information about the cast member.

    What I would like to do is on the cast members page display a list of every product the cast member has been involved with.

    Hope that makes sense.

  • Having investigated further I feel that a bidirectional relationship between the cast member and the event will work best. However, I cannot seem to find any information in relation to bidirectional relationships within a repeater. I require a repeater so that I can have a list of multiple cast members assigned to different characters.

    Is this something that can be done? I have noticed a few other help topics on this that have had no answers. Obviously, this is something people want.

  • I don’t think that a bidirectional relationship field here is really what you need. Making a bidirectional field implies that when you are editing the cast member you can select what productions they are in, which would mean another repeater field so that you can also enter character names on the member page and there would also need to be a way to check these two repeaters to make sure that these 2 repeater field match up. This is all possible, but difficult and probably overkill for what you want to do.

    Instead I would not use an ACF field on the cast member side. I would use a standard WP meta field. Still not all that easy though.

    I don’t have code, and I don’t know of any existing code to use as an example, but this would work similarly to a by directional field. The difference is that you’d need to use an acf/save_post filter with a low priority (<10) so that you can compare the old rows of the repeater with the new rows. You’d need to figure out what relationships need to be removed and which need to be added. Then you’d need to get each of the member posts and update the value on the other end.

  • Thanks for the info, ill have a look into it, I can see how that would work now just need to make it a reality haha.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Nested Relationship Backward query’ is closed to new replies.