Hello,
I have a Cred that is used to create messages.
No issue at that time.
Now, I need to change the created post author and replace it by a field managed in the Cred (visitor_id)
How can I do this?
Regards
Pat
Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Well - you should use the Toolset form's hook "cred_save_data" to update the post author for created post.
For example:
- Please try to add following code to your current theme's functionns.php file
OR
- Custom code section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
add_action('cred_save_data', 'func_update_post_author',30,2);
function func_update_post_author($post_id, $form_data){
if ($form_data['id']==9999){
$post_args = array(
'ID' => $post_id,
'post_author' => 7777, // replace with your visitor_id variable $_POST['visitor_id'] or $_POST['wpcf-visitor_id']
);
// update post author
wp_update_post( $post_args );
}
}
Where
- replace 9999 with original form ID
More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
Hi Minesh,
Many thanks for your support.
Regards
Pat