Skip Navigation

[Resolved] How to set the post title from a custom post field value

This support ticket is created 3 years 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 3 voices.

Last updated by morenoT 3 years ago.

Assisted by: Shane.

Author
Posts
#2355211

Hi,
when saving the input/edit form I'd like to automatically set the post title from a custom post field value named (slug) "titolo-priorita". How can I do?

Thank you!

Moreno

#2355279

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

Is this when users submit a front-end form? (Rather than editing a post in the back end.)

In which case you can use the cred_save_data hook to run some code to update the title based on the value of your custom field.

There is an example (the last example) in the documentation for cred_save_data, see: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

If you don't understand the example and need some help, let us know and we can offer more guidance.

#2355433

Hi,

I've tried to apply this hook in Toolset/Settings/Custom code:
// Put the code of your snippet below this comment.
// AGGIORNA TITOLO DOC PRIORITA
add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
if ($form_data['id']==346) {
$field_1 = $_POST['wpcf-titolo-documento']
$args = array('ID' => $post_id, 'post_title' => $field_1);
wp_update_post($args);
}
}
But it's not working and it gives me this error:

syntax error, unexpected '$args' (T_VARIABLE) in /var/www/html/pand-dpa.it/wp-content/toolset-customizations/set-post-title.php on line 15

A problem occurred when executing snippet "set-post-title-priorita". The result of include_once is: ""

Note: Depending on the nature of the error, you may need to run the script in a particular scenario to make sure the issue is gone.

Thank you for helping.

Moreno

#2355513

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Moreno,

I took a look at the code and saw that you were missing a semicolon at this line below.

$field_1 = $_POST['wpcf-titolo-documento']

It should be

$field_1 = $_POST['wpcf-titolo-documento'];

This should resolve your issue.

Thanks,
Shane

#2355523

My issue is resolved now. Thank you!