Skip to content

Instantly share code, notes, and snippets.

@g-maclean
Created January 22, 2026 09:45
Show Gist options
  • Select an option

  • Save g-maclean/e3dac7296399c9d822212efd801cdcdc to your computer and use it in GitHub Desktop.

Select an option

Save g-maclean/e3dac7296399c9d822212efd801cdcdc to your computer and use it in GitHub Desktop.
Property Hive - Reapit Foundations - Use address fields for Locations
// for use when the embedded area isn't populated or doesn't work for some reason
add_action( "propertyhive_property_imported_reapit_foundations_json", "assign_location_from_multiple_fields", 10, 2 );
function assign_location_from_multiple_fields( $post_id, $property ) {
$location_set = false;
$fields_to_check = array( 'line2', 'line3' );
foreach ( $fields_to_check as $field ) {
if ( isset( $property['address'][ $field ] ) && trim( $property['address'][ $field ] ) != '' ) {
$reapit_location = trim( $property['address'][ $field ] );
$term = term_exists( $reapit_location, 'location' );
if ( $term !== 0 && $term !== null && isset( $term['term_id'] ) ) {
$location_set = true;
wp_set_object_terms( $post_id, array( (int)$term['term_id'] ), 'location' );
break; // Exit loop once a location is set
}
}
}
if ( !$location_set )
{
wp_delete_object_term_relationships( $post_id, 'location' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment