Hi,
I am creating a CRED form to add posts of a CPT called "Books".
The form works perfectly fine. except that I can't find a "post slug" field.
I need to be able to adjust some of my post slugs.
I tried the following codes, but none of them worked:
You need to use CRED hook cred_save_data in order to rename the slug for newly added post.
For example - you should adjust the below code as per your need to build your custom slug (post_name):
add_action("cred_save_data", "my_save_data_action",10,2);
function my_save_data_action($post_id, $form_data)
{
global $current_user;
// if a specific form
if ($form_data["id"]==9999)
{
$username = $current_user->user_nicename;
$date = get_the_date();
$title = $username."--".$date;
// Update the post into the database
$my_post = array(
'ID' => $post_id,
'post_title' => $title,
'post_name' => $title
);
wp_update_post( $my_post );
}
}
Where:
- Replace 9999 with your original CRED form ID