Hi,
I would like to generate a title when submitting a form. A static text, and the post ID.
Like this: Form number: 1009
*****
I have tried using this code:
function my_save_data_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==1179){
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$custom_title = get_post_meta( $post_id, 'wpcf-bh-1', true );
//collect data and define new title
$my_post = array(
'ID' => $post_id,
'post_title' => $custom_title,
'post_name' => $custom_title,
);
// Update the post into the database
wp_update_post( $my_post );
}
}
add_action('cred_save_data', 'my_save_data_action',10,2);
***
I am able to pull the value from that custom field, but I have no ide how to make a static text and how to pull the post ID into this form and render page.
Hello,
Please elaborate the questions with more details:
I have no ide how to make a static text and how to pull the post ID into this form and render page.
What kind of static text do you need?
You can get the post ID value from variable $post_id, it is the post ID value.
Hi Luo,
I will try to explain better.
I have made a form for frontend posting. The form does not have a field to create a title, because this title should not be typed in by user but generated from wordpress / toolset
The generated title should be the word: Form number:, and then the ID of the post created.
Like this: Form number 10023
****
1: The title field is not visible in form
2: The generated title is visible in single post view, archive and others.
****
I was hoping a minor tweek to this approach could solve this.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
Thanks for the details, you can modify this line from:
$custom_title = get_post_meta( $post_id, 'wpcf-bh-1', true );
To:
$custom_title = 'Form number ' . $post_id;
And test again.
Great, it now works!
My issue is resolved now. Thank you!