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
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.
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
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
My issue is resolved now. Thank you!