/ Published in: PHP
Breaks up an address (in this case returned by Advanced Custom Fields Location plugin) into it's components. Additionally, sorts a multidimensional array of locations alphabetically by state. This works for basic addresses assuming that address is in the format 'street, city, state, zip, country.' I've written a more extensive version of this snippit that uses Google Geocoding to get the address components and store them in a Wordpress database as meta data.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function break_address( $loc ) { 'state' => $state_zip[0], 'zip' => $state_zip[1], ); return $components_array; } $location = get_field( 'location_field' ); $location = $location[ 'address' ]; $locations[ 0 ] = break_address( $location ); { return $a[ 'state' ] - $b[ 'state' ]; });