Hi,
thanks for your help, but it still returns 0.
I did my code like this:
add_action('cred_save_data','address_update',10,2);
function address_update($post_id,$form_data) {
// ID 26 - CRED
if ($form_data['id']==26) {
$jobaddress = get_post_meta ( $post_id, "wpcf-adresse-choice", true );
$job_id = $post_id;
//Adresse vom Hauptstandort (Post --> Unternehmen)
if ($jobaddress=="1"){
//Get related Business ID
$business_id = toolset_get_related_post( $job_id , 'business-job' );
$address_field = array('staat'=>'wpcf-staat','postleitzahl'=>'wpcf-postleitzahl','stadt'=>'wpcf-stadt','strasse'=>'wpcf-strasse','hausnummer'=>'wpcf-hausnummer');
$address_field_region = array('region-at'=>'wpcf-bundesland-at','region-de'=>'wpcf-bundesland-de','region-ch'=>'wpcf-bundesland-ch');
foreach ($address_field as $key => $field){
$address_field[$key] = get_post_meta ( $business_id, $field, true );
}
foreach ($address_field_region as $key => $field){
$address_field_region[] = get_post_meta( $business_id, $field, true );
}
//clear empty elements --> only one content
$address_field_region = array_filter($address_field_region);
//add region to array
$address_field[region] = $address_field_region[0];
// address in one line
$address_one_line = implode(", ", $address_field);
// add address to array
$address_field[adresse] = $address_one_line;
foreach ($address_field as $key => $field) {
if ( ! add_post_meta( $job_id, 'wpcf-'.$key, $field, true ) ) {
update_post_meta( $job_id, 'wpcf-'.$key, $field );
}
}
}
if ($jobaddress=="2"){
//Get related location ID
$location_id = toolset_get_related_post( $job_id , 'location-job' );
$address_field = array('staat'=>'wpcf-staat','postleitzahl'=>'wpcf-postleitzahl','stadt'=>'wpcf-stadt','strasse'=>'wpcf-strasse','hausnummer'=>'wpcf-hausnummer');
$address_field_region = array('region-at'=>'wpcf-bundesland-at','region-de'=>'wpcf-bundesland-de','region-ch'=>'wpcf-bundesland-ch');
foreach ($address_field as $key => $field){
$address_field[$key] = get_post_meta ( $location_id, $field, true );
}
foreach ($address_field_region as $key => $field){
$address_field_region[] = get_post_meta( $location_id, $field, true );
}
//clear empty elements --> only one content
$address_field_region = array_filter($address_field_region);
//add region to array
$address_field[region] = $address_field_region[0];
// address in one line
$address_one_line = implode(", ", $address_field);
// add address to array
$address_field[adresse] = $address_one_line;
foreach ($address_field as $key => $field) {
if ( ! add_post_meta( $post_id, 'wpcf-'.$key, $field ,true ) ) {
update_post_meta( $post_id, 'wpcf-'.$key, $field );
}
}
}
}
}
I costumized it a little bit, but the code within the if-loops works, i tested it by setting the ID hardcoded.
Like you see the users can relate the job-post either to a business-post or to a location-post, with the result of updating the address of the job-post.
Thanks Ben