Skip to navigation Skip to content
OTGS Knowledge Base
  • Login
  • Home

Copy value of child custom field to another, from Parent Post

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);
}
Tags: legacy_types_api, post-relationship, update_post_meta
OnTheGoSystems - One team, one goal

Report Post

« »

 

Your Name:

Your Email:

Please tell us why do you think this post is inappropriate and shouldn't be there:


Cancel Report