Tell us what you are trying to do? create a child post using a from and give it a dynamic name with data from the parent post
Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/displaying-parent-posts/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
https://toolset.com/forums/topic/cannot-get-parent-post-id-on-cred_save_data-with-new-relationships-api/#post-1121934
Is there a similar example that we can see?
not sure
What is the link to your site?
hidden link
I have tried multiple solutions but couldn't get this to work.
i can create a dynamic name for a post but cannot get the parent data to insert to the child post.
both parent and child posts are with status Private
here is one of the codes i tried
//Create a dynamic post title by the CRED form.
add_action('cred_save_data', 'func_custom_post_title', 10, 2);
function func_custom_post_title($post_id, $form_data)
{
$author = get_the_author();
$user_id = get_the_author_meta('ID');
//if new client - parent post dynamic name works just fine
if ($form_data['id'] == 283 ) {
$author = get_the_author();
$user_id = get_the_author_meta('ID');
$post_type = get_post_type( $post_id );
$cfn = get_post_meta($post_id, 'wpcf-client-first-name', true);
$cln = get_post_meta($post_id, 'wpcf-client-last-name', true);
$cshrtid = get_post_meta($post_id, 'wpcf-client-id-number', true);
$title = $cfn.' '.$cln.' '.$user_id.'-'.$cshrtid.'-'.$post_id;
$slug = sanitize_title($title);
$args = array('ID' => $post_id, 'post_title' => $title, 'post_name'=>$slug);
wp_update_post($args);
}
//if new portfolio -child post cannot get the parent post data so this is not working
if ($form_data['id'] == 386 ) {
//get data from parent post i tried this option
$parent_post_id = toolset_get_related_post( $post_id, 'client-client-portfolio', 'client' );
// and i tried this option
$child_post_id = get_post($post_id);
$parent_post_id = toolset_get_related_post( $child_post_id, 'client-client-portfolio', 'parent');
$cfn = get_post_meta($parent_post_id, 'wpcf-client-first-name', true);
$cln = get_post_meta($parent_post_id, 'wpcf-client-last-name', true);
$cshrtid = get_post_meta($parent_post_id, 'wpcf-client-id-number', true);
//get data from current post
//$post_type = get_post_type( $post_id );
// Get the title of the parent (client) post
$title = $cfn.' '.$cln.' '.$user_id.'-'.$cshrtid.'-'.$parent_post_id.'-P'.$post_id;
$slug = sanitize_title($title);
$args = array('ID' => $post_id, 'post_title' => $title, 'post_name'=>$slug);
wp_update_post($args);
}
}
please advise,
thanks,
David