Skip Navigation

[Resuelto] Populate post custom fields with parent custom field value

This support ticket is created hace 2 años, 7 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 – 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/Hong_Kong (GMT+08:00)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Luo Yang hace 2 años, 7 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#2351087

Hello,

I'm trying to update a post field with a field value of the parent post.

Following exactly this post: https://toolset.com/forums/topic/populate-relationship-m2m-custom-fields-with-parent-child-titles/

I need to do like this BUT instead of post_title use a custom field value:

update_post_meta( $post->ID, $field_for_parent_slug, $get_results[0]['parent']->post_title );

I tried like this but didn't work:

update_post_meta( $post->ID, $field_parent_field_for_parent_slug, $get_results[0]['parent']->'wpcf-parent-field-slug' );
#2351331

Hello,

Please try to modify the codes you mentioned above from:

...
update_post_meta( $post->ID, $field_parent_field_for_parent_slug, $get_results[0]['parent']->'wpcf-parent-field-slug' );
...

To:

...
$parent_post_id = $get_results[0]['parent']->ID;
$parent_field_value = get_post_meta($parent_post_id, 'wpcf-parent-field-slug', true);
update_post_meta( $post->ID, $field_parent_field_for_parent_slug, $parent_field_value);
...

More help:
https://developer.wordpress.org/reference/functions/get_post_meta/