Created
February 6, 2026 12:29
-
-
Save g-maclean/d7f66193339b45862462d07217e773c8 to your computer and use it in GitHub Desktop.
Property Hive - Street - Use Line 2 if it is the number + street address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'propertyhive_property_imported_street_json', function( $post_id, $property ) { | |
| if ( empty( $property['address']['line_2'] ) ) { | |
| return; // nothing to do | |
| } | |
| $line_2 = trim( $property['address']['line_2'] ); | |
| $parts = explode( ' ', $line_2 ); | |
| // Match: 100, 100b, 12A etc | |
| if ( ! preg_match( '/^\d+[a-zA-Z]?$/', $parts[0] ) ) { | |
| return; // line_1 logic already handles everything else | |
| } | |
| $address_number = array_shift( $parts ); | |
| $address_street = implode( ' ', $parts ); | |
| update_post_meta( $post_id, '_address_name_number', $address_number ); | |
| update_post_meta( $post_id, '_address_street', $address_street ); | |
| }, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment