Tell us what you are trying to do?
I have two post types: Studios and Artists. A Studio can have many Artists, and an Artist can belong to many Studios (set up as a many-many relationship). I have Toolset forms to create each post type.
Documentation: https://toolset.com/forums/topic/automatically-connecting-post-types-in-many-many-relationship/#post-1074784
I follow the steps as in the documentation:
1) You are using below many-many relationship, the relationship slug is "studio-artist", you can get the relationship slug by editing the many-many relationship, make sure "studio" post type is in the left place of the relationship, and "artist" post type is in the right place.
2) In the single "studio" post, you can display a Toolset post form for creating "artist" post
3) In the Toolset post form, you can get the current "studio" post ID with Views shortcode
[wpv-post-id], use it in a hidden field "studio_id", and pass parameter to Toolset form, for example:
[cred_generic_field field='studio_id' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-id]"
}
[/cred_generic_field]
4) Use action hook cred_save_data to trigger a custom PHP function, in this function connect the "studio" post with the new "artist" post, like this:
add_action('cred_save_data', 'connect_studio_artist_func',10,2);
function connect_studio_artist_func($artist_id, $form_data)
{
// if a specific form
if ($form_data['id']== 35 && isset($_POST['studio_id']))
{
$studio_id = $_POST['studio_id'];
if($studio_id){
toolset_connect_posts(
$relationship = 'studio-artist',
$studio_id,
$artist_id
);
}
}
}
It works perfectly. However in my case, I also need an intermediary post. How do I insert the id of the intermediary post in the toolset_connect_posts( $relationship = 'studio-artist', $studio_id, $artist_id); ? Is it toolset_connect_posts( $relationship = 'studio-artist', $studio_id, $artist_id, $intermediary_id); ?
Something like..
add_action('cred_save_data', 'connect_studio_artist_func',10,2);
function connect_studio_artist_func($artist_id, $form_data)
{
// if a specific form
if ($form_data['id']== 35 && isset($_POST['studio_id']))
{
$studio_id = $_POST['studio_id'];
if($studio_id){
// Create post object
$intermediary = array(
'post_title' => 'dynamic',
'post_status' => 'publish',
'post_type' => 'booking-times',
'post_author' => $studio_id,
);
// Insert the post into the database
$intermediary_id = wp_insert_post( $intermediary );
toolset_connect_posts(
$relationship = 'studio-artist',
$studio_id,
$artist_id,
$intermediary_id
);
}
}
}
Is there any documentation that you are following?
https://toolset.com/forums/topic/automatically-connecting-post-types-in-many-many-relationship/#post-1074784
https://toolset.com/forums/topic/relationship-of-dynamically-created-child-post/
Is there a similar example that we can see?
In the documentation
What is the link to your site?
hidden link