Tell us what you are trying to do? get_post_meta from parent when saving new child using cred form
Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
https://toolset.com/forums/topic/getting-parent_id-in-toolset-3-0-using-get_post_meta-function/
https://toolset.com/forums/topic/cannot-get-parent-post-id-on-cred_save_data-with-new-relationships-api/#post-1121934
https://toolset.com/forums/topic/get-post-parent-witn-new-relationship-model-php/#post-909071
Is there a similar example that we can see?
https://toolset.com/documentation/customizing-sites-using-php/displaying-parent-posts/
What is the link to your site?
enlace oculto
i tried to get the parent post id using a few methods in order to retrieve parent post metadata to be used in the name of the child post created with cred form
here is the code i used:
//Create a dynamic post title by the CRED form.
add_action('cred_save_data', 'func_custom_post_title', 50, 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 NAMING - THIS if STATEMENT IS WORKING 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 NAMING - THIS if STATEMENT DOES NOT GET THE PARENT POST ID
if ($form_data['id'] == 386 ) {
//get data from parent post
$parent_post_id = toolset_get_related_post($post_id, 'client-client-portfolio' );
$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);
}
}
after the post is created i see that the name doesn't have the parent post metadata i was looking for.
i tried many variations to get the parent post id with no success.
Please advise,
thanks,
David