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' );
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/