Skip Navigation

[Resolved] Help saving a custom field as the post title

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Minesh 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2612799

Hi there,

I'm trying to create a contact form that saves posts. Sort of like a in build ticketing system.

I'm using a drop down custom field with the title wpcf-post_title to set the title.

I'm using this code:

function set_custom_post_title( $args, $form_id, $form_data ) {
// Check if the form ID matches the desired form
if ( $form_id === 151341 ) {
// Get the value of the custom field 'wpcf-post_title' from the submitted form data
$custom_title = $form_data['fields']['wpcf-post_title'];

// Set the post title to the value of the custom field
$args['post_title'] = $custom_title;
}

return $args;
}
add_filter( 'cred_save_data', 'set_custom_post_title', 10, 3 );

But it seems to give me an error.

Could you point me in the right direction?

#2612879

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please tell me what you setup as option value for your dropdown select where user can select the post title?

It would be great if you can share problem URL where you added the form and I will get back to you with the possible solution.

#2612921

Hi Minesh,

How can i share details with you in private?

#2612927

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I have set the next reply to private which means only you and I have access to it.

#2612929
Screenshot 2023-06-06 at 7.07.50 pm.png

Thought we might ale to start with a screenshot.

The user is already logged in when submitting the form. The subject field decscription, rather than value would be great saved as the post title, maybe with their username next to it. For example; General Support - @username

Best regards
Kyle

#2613321

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can use the Toolset Form's hook "cred_save_data" as given under:

For example:
- Please try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data) {
 
if ($form_data['id']==9999) {
$title =$_POST['wpcf-post_title'];
$username = $_POST['wpcf-username'];
  
$post_title  =   $title .'- Support -'.$username;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}

Where:
- Replace 9999 with your CRED form ID.
- Adjust the custom field slugs where required for post_title and username

Please check the following Doc:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Related Tickets you may interested in:
=> https://toolset.com/forums/topic/adding-two-custom-fields-together-to-make-a-post-title-on-submit/#post-412305