Skip Navigation

[Resolved] Define a custom post title using information from the FORM

This support ticket is created 5 years, 1 month 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/Karachi (GMT+05:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 5 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1214115

Tell us what you are trying to do?
I have a frontend form, I need to define the title with some information submitted inside the form.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1214208

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Enrique,

Thank you for waiting.

This following code snippet will make you better understand how the "cred_save_data" hook works.

Suppose that you have a Toolset form with ID "123" with a field with slugs "field-slug-1" and "field-slug-2". And you'd like to use the first field's value for the post title and the second one for the post's slug.

In this case, the code that you'll add in your active theme's "functions.php" file would be:


add_action('cred_save_data','custom_title_slug_func',15,2);
function custom_title_slug_func($post_id, $form_data) {
	if ($form_data['id']==123) {

		// get the value of fields
		$field_1 = $_POST['wpcf-field-slug-1'];
		$field_2 = $_POST['wpcf-field-slug-2'];

		// set the values of fields in title and slug
		$title 	= $field_1;
		$slug 	= $field_2;

		$my_post_data = array(
			'ID'			=> $post_id,
			'post_title'	=> $title,
			'post_name'		=> sanitize_title($slug),
		);

		// Update the post into the database
		wp_update_post( $my_post_data );

	}
}

Feel free to adjust this snippet to match your website's form and custom field values, as needed.

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

#1214820

Hello!

I installed this as a plugin but the post is saved with no title, I replaced everything as you told me. thanks

#1215347

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Enrique,

Sorry to learn that the suggested code example doesn't work.

For further investigation into this, it would help if you could share the clone or snapshot of your website.
(it can be from this website or from another test website where the issue is reproducible)

We usually recommend the free Plugin “Duplicator” (http://wordpress.org/plugins/duplicator/) for this purpose.

If you already know how Duplicator works, you can skip the instruction video and just send me the installer file and the zipped package you downloaded.

Duplicator Instructions:
hidden link

( note: I'll need both files and you'll probably want to use DropBox, Google Drive, or similar services, as the snapshot file will be quite big )

IMPORTANT: Remember to create or keep an admin account for me before creating the snapshot, or I won’t be able to log in. You may delete the new admin account once the snapshot has been built.

I will set your next answer as private so you can provide me the information securely.

regards,
Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.