[Resuelto] On submit form. Take the value from a field to another field.
This support ticket is created hace 3 años, 3 meses. 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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
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)
Este tema contiene 7 respuestas, tiene 2 mensajes.
With the next code, in the WordPress admin, I can generate the value of the field "email-comercial-asociado" depending on the relationship field "comercial-expediente". But now, I want to do the same but when creating the post from a front-end form.
add_action( 'save_post', 'copy_relation_to_field_email_for_recomendado', 100, 3 );
function copy_relation_to_field_email_for_recomendado( $post_id, $post, $update ) {
if ( $post->post_status == 'publish' && $post->post_type == 'recomendado' ) {
$recomendado_id = $post_id;
// Get ID from CPT "comercial" parent of CPT "recomendado"
$comercial_id = toolset_get_related_post( $recomendado_id, 'comercial-expediente', 'parent');
$author_comercial_id = get_post_field( 'post_author', $comercial_id );
$author_coemrcial_email = get_the_author_meta( 'email', $author_comercial_id );
// Update custom field
update_post_meta( $post_id, 'wpcf-email-comercial-asociado', $author_coemrcial_email );
}
}
The first code run ok, but I modify it to use it with the front-end form and it doesn't work:
But I modify it to use it from the form and it doesn't work:
add_action('cred_save_data', 'copy_relation_to_field_email_for_recomendado_frontend',999,2);
function copy_relation_to_field_email_for_recomendado_frontend($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==335)
{
if (isset($_POST['@comercial-expediente.parent']))
{
$recomendado_id = $post_id;
// Cogemos el ID del CPT comercial padre del recomendado
$comercial_id = toolset_get_related_post( $recomendado_id, 'comercial-expediente', 'parent');
$author_comercial_id = get_post_field( 'post_author', $comercial_id );
$author_coemrcial_email = get_the_author_meta( 'email', $author_comercial_id );
// add it to saved post meta
add_post_meta($post_id, 'wpcf-email-comercial-asociado', $author_coemrcial_email);
}
}
}
I'm not seeing any reason why this shouldn't work.
Would you mind allowing me to have admin access to the site as well as a link to the page where you are testing this so that I can do a firsthand check ?