Copying a value from a child posts custom field to another one, when saving the parent post in the Admin.
There is an action for when we hit Save All child on parent post page (Types).
It’s wpcf_relationship_save_child
and has two arguments, $child
and $parent
. Both are objects.
add_action( 'wpcf_relationship_save_child', 'wpcf_date_relationship_save_child', 10, 2 ); function wpcf_date_relationship_save_child( $child, $parent ) { $date = get_post_meta($child->ID, 'wpcf-start-date', true); $month = date('Y', $date); $year= date("M",$date); update_post_meta($child->ID, 'start_month', $month); update_post_meta($child->ID, 'start_year', $year); }