I am trying to:
My issue concerns creating multiple connections between two posts in related custom post types. The use case involves two post types: "Personnel" and "Locations". Personnel can be assigned to multiple Locations, and a Location can have multiple Personnel assigned (many-to-many). A Person may be assigned to a Location more than once at different dates. I want to create a history of Personnel-Location assignments using date fields in the intermediary post type.
This use case seems to be similar to that described in https://toolset.com/forums/topic/creating-repeat-multiple-connections-to-the-same-items/
I understand that the expected behaviour is that the same items cannot be connected more than once. Is there a workaround you can suggest?
Link to a page where the issue can be seen:
My page is offline, developed on localhost.
I expected to see:
Ability to record multiple instances of the same personnel-location with different dates stored in the intermediary post type.
Instead, I got:
Only one instance of a personnel-location combination can be stored.
Hi, one workaround I'm aware of is to use two one-to-many (O2M) relationships instead of one many-to-many (M2M) relationship. In the workaround, you manually create the intermediary post type like you would create any other basic post type. Then you can add a start date custom field and end date custom field. After that, set up an O2M relationship between Personnel and the intermediary post type, and another O2M relationship between Location and intermediary post type. Now you can create as many intermediary posts as you would like, and link them to the same two parent posts. This will give you multiple instances of relationship between the same two parent posts, complete with a timeline.
A word of caution: this workaround isn't always useful if you need robust View filtering and searching capabilities. It's fine for displaying related posts, but complex queries can get messy. If you have questions about that, let me know.
Thanks Christian, this looks promising. So far I have done the following:
Manually created the CPT "Personnel Locations"
Set up a O2M relationship between "Personnel" and "Personnel Locations"
Set up a O2M relationship between "Locations and "Personnel Locations"
Created a Personnel Location test post "Test Posting 1" with start and end dates.
Connected "Test Posting 1" to "Person A" and "Location A"
Created a Personnel Location test post "Test Posting 2" with different start and end dates.
Connected "Test Posting 2" to "Person A" and "Location A"
Next on the post for "Person A" I would like to show a table displaying a row for each history entry. The row should contain the name of the location (post title with link), start date and end date. Will this involve a complex query? So far I've tried the following:
Created view "Test Personnel Location View" displaying "Personnel Location" post types.
Added a filter by post relationship between "Personnel" and "Personnel Locations" to select related items of the post where this view is shown.
Used the Loop Wizard to include fields "Start Date" and "End Date" for The current post being displayed either directly or in a View loop.
Edit: Added to the view loop post title with link, selected by A post related to the current post, set by a Types relationship for "Locations" in the Location-Personnel Location relationship.
Added the view "Test Personnel Location View" to the layout for Personnel.
Edit: All seems to be working as desired now.
Thanks again for your help.
Geoff
Great, this sounds like what I had in mind. Hope you're able to continue your project successfully now.