Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function em_location_by_region(){
- $args = array();
- $arr_location = EM_Locations::get($args);
- /*Get regions as header*/
- $arr_region = array();
- foreach ( $arr_location as $EM_Location_region ) {
- if ( !in_array($EM_Location_region->region,$arr_region) && !empty($EM_Location_region->region) ){
- array_push($arr_region,$EM_Location_region->region);
- }
- }
- /*Get state*/
- $arr_state = array();
- $arr_region_state = array();
- foreach ( $arr_region as $key => $value ) {
- foreach ( $arr_location as $EM_Location_state ) {
- if ( $EM_Location_state->region == $value ){
- array_push($arr_state,'<a href="'.$EM_Location_state->get_permalink().'">'.$EM_Location_state->name.'</a>');
- }
- }
- $arr_region_state[$value] = $arr_state;
- if ( !empty($arr_state) )$arr_state = array();
- }
- ksort($arr_region_state);
- /*display the result*/
- foreach ( $arr_region_state as $key => $value ) {
- echo '<h2>'.$key.'</h2>';
- echo '<ul>';
- foreach ( $value as $em_state ) {
- echo '<li>'.$em_state.'</li>';
- }
- echo '</ul>';
- }
- }
- add_shortcode('location_group', 'em_location_by_region');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement