Reply To: Multiple Fields for Address Custom Field

Home Forums MapPress Support Multiple Fields for Address Custom Field Reply To: Multiple Fields for Address Custom Field

#10132
metropoliscreative
Participant

hi Chris,

As a follow-up, I think I ALMOST have it working through this function which I placed in functions.php.  The only issue now is: the custom field “Address Complete” will be filled with the meta from the other boxes if it is empty but will not overwrite if there is something already there!  If I can figure out that one thing I think this should do it.  Any idea?

 

// AUTO COMBINE CUSTOM FIELDS ON LOCATIONS
add_action('publish_locations', 'add_custom_field_automatically');
add_action('update_locations', 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
global $wpdb;
get_post_custom($GLOBALS['post']->ID);
$add1 = get_post_meta( $GLOBALS['post']->ID, 'Address Line 1', true );
$add2 = get_post_meta( $GLOBALS['post']->ID, 'Address Line 2', true );
$addcity = get_post_meta( $GLOBALS['post']->ID, 'City', true );
$addzip = get_post_meta( $GLOBALS['post']->ID, 'Zip Code', true );
$addcomp= $add1 . ' ' . $add2 . ' ' . $addcity . ' ' . $addzip;
if(!wp_is_post_revision($post_ID)) {
add_post_meta($post_ID, 'Address Complete', $addcomp, false) or update_post_meta($post_ID, 'Address Complete', $addcomp, false);
}
}