Hi Lane,
Thank you for contacting us and I'll be happy to assist.
Based on my tests, the newly created child post's title (through a new post form) uses default text like "CRED Auto Draft ...", when the post title field is not available or is left empty.
For points 1 & 2, you can extract the ID of the selected parent post from the "$_POST" variable ( ref: hidden link ), in a function attached to the "cred_save_data" hook.
Here is an example that worked on my website:
add_action('cred_save_data','custom_title_slug_func',15,2);
function custom_title_slug_func($post_id, $form_data) {
if ($form_data['id']==204) {
// set the values of fields in title and slug
$title = get_the_title($_POST['@shop-book_parent'])."-child";
$slug = sanitize_title($title).'-'.$post_id;
$my_post_data = array(
'ID' => $post_id,
'post_title' => $title,
'post_name' => $slug,
);
// Update the post into the database
wp_update_post( $my_post_data );
}
}
Notes:
- Please replace "204" with the actual ID of your post form and "shop-book_parent" with the actual field name for your parent field.
- In this example, I've appended "-child" to the title and current post's ID to the slug to make it unique.
For point 3, if your goal is to redirect the visitor to the selected parent post after the form is submitted, you can use the "cred_success_redirect" hook to get the ID and the permalink for the parent post, using the same $_POST variable.
( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect )
Example:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
if ($form_data['id']==204)
$url = get_permalink($_POST['@shop-book_parent']);
return $url;
}
I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar