Skip Navigation

[Resolved] Custom title from post form

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by samuelH 5 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1323883

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.

#1324041

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.

#1324113

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

#1324131

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.

#1325121

Great, it now works!

My issue is resolved now. Thank you!