admin_url('admin-ajax.php') ); wp_localize_script( 'acf_ngmdl_js', 'acf_ngmdl', $translation_array ); // Enqueue Style wp_enqueue_style('acf_ngmdl'); // Enqueue Script wp_enqueue_script('google-api'); wp_enqueue_script('google-api-marker-cluster'); wp_enqueue_script('acf_ngmdl_js'); } /* * acf_ngmdl_do_shortcode * * @description: Shortcode Start * @since: 1.0 * @created: 21/09/14 */ public function acf_ngmdl_do_shortcode($atts){ // Attributes extract( shortcode_atts( array( 'cat' => 'all', 'height' => '480px', 'width' => '100%', 'filter' => 1 ), $atts ) ); // Set Height if (strpos($height,'px') !== false) { $height_px = $height.'px'; } elseif (strpos($height,'%') !== false) { $height_px = $height.'%'; } else { $height_px = $height; } // Set Width if (strpos($width,'px') !== false) { $width_px = $width.'px'; } elseif (strpos($height,'%') !== false) { $width_px = $width.'%'; } else { $width_px = $width; } $args = array( //Type & Status Parameters 'post_type' => 'acf_maps', 'post_status' => 'publish', //Pagination Parameters 'posts_per_page' => -1, ); $terms = ''; if ($cat != 'all'){ $category = array_filter(explode(',', $cat)); $terms = $this->acf_ngmdl_get_terms_id_list($category); $posttype = 'acf_maps_category'; $args = array( //Type & Status Parameters 'post_type' => 'acf_maps', 'post_status' => 'publish', //Pagination Parameters 'posts_per_page' => -1, //Taxonomy Parameters 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => $posttype, 'field' => 'id', 'terms' => $terms, 'include_children' => true, 'operator' => 'IN' ) ), ); } $the_query = new WP_Query( $args ); $found = $the_query->found_posts; $markers = ''; if ( $the_query->have_posts() ) { $i = 0; while ( $the_query->have_posts() ) { $the_query->the_post(); $post_id = get_the_ID(); $categories = get_the_terms($post_id, 'acf_maps_category'); $cat_id_name = array(); foreach ( $categories as $category ) { $inner = array(); $inner['id'] = $category->term_id; $inner['name'] = $category->name; $cat_id_name[] = $inner; } $map_details = get_field( 'acf_ngmdl_map_details', $post_id); if ($map_details && !empty($map_details['address']) && !empty($map_details['lat']) && !empty($map_details['lng']) ){ $markers[$i] = $map_details; $markers[$i]['id'] = $post_id; $markers[$i]['title'] = get_the_title(); $markers[$i]['category'] = $cat_id_name; $markers[$i]['phone'] = get_field( 'acf_ngmdl_location_contact', $post_id); $markers[$i]['url'] = get_field( 'acf_ngmdl_location_url', $post_id); $markers[$i]['other'] = get_field( 'acf_ngmdl_location_other', $post_id); $i++; } } } // Restore original Post Data wp_reset_postdata(); $return = ''; $marker_instances = ''; // if ($markers){ foreach ($markers as $marker) { $lng = $marker['lng']; $lat = $marker['lat']; $address = isset($marker['address']) ? $marker['address'] : ''; $title = isset($marker['title']) ? $marker['title'] : ''; $phone = isset($marker['phone']) ? $marker['phone'] : ''; $url = isset($marker['url']) ? $marker['url'] : ''; $other = isset($marker['other']) ? $marker['other'] : ''; $mail_to = ''; if (strpos($url,'@') !== false) { $mail_to = "mailto:"; } if ($address != '') : $marker_instances .= ""; endif; } // } $return .= "
".$marker_instances."
"; if ($filter){ $return .= $this->acf_ngmdl_listing_tab($terms); } $return .= '
'; // Display the content return $return; } /* * acf_ngmdl_listing_tab * * @description: Add filtering list * @since: 1.0 * @created: 21/09/14 */ public function acf_ngmdl_listing_tab($terms=''){ $taxonomy = 'acf_maps_category'; $args = array( 'hide_empty' => true, 'parent' => 0, 'include' => $terms ); $parents = get_terms($taxonomy, $args); $list = ''; foreach ($parents as $parent => $value) { $list .= ''; $children = get_terms( $taxonomy, array('child_of' => $value->term_id) ); $sub_list = ''; foreach ($children as $child => $c_value) { $sub_list .= ''; } if (!empty($sub_list)){ $list .= $sub_list; } } ?>
'acf_maps', 'post_status' => 'publish', //Pagination Parameters 'posts_per_page' => -1, //Taxonomy Parameters 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => $posttype, 'field' => 'id', 'terms' => $category, 'include_children' => true, 'operator' => 'IN' ) ), ); $the_query = new WP_Query( $args ); $found = $the_query->found_posts; $markers = ''; if ( $the_query->have_posts() ) { $i = 0; while ( $the_query->have_posts() ) { $the_query->the_post(); $post_id = get_the_ID(); $categories = get_the_terms($post_id, 'acf_maps_category'); $cat_id_name = array(); foreach ( $categories as $category ) { $inner = array(); $inner['id'] = $category->term_id; $inner['name'] = $category->name; $cat_id_name[] = $inner; } $map_details = get_field( 'acf_ngmdl_map_details', $post_id); if ($map_details && !empty($map_details['address']) && !empty($map_details['lat']) && !empty($map_details['lng']) ){ $markers[$i] = $map_details; $markers[$i]['id'] = $post_id; $markers[$i]['title'] = get_the_title(); $markers[$i]['category'] = $cat_id_name; $markers[$i]['phone'] = get_field( 'acf_ngmdl_location_contact', $post_id); $markers[$i]['url'] = get_field( 'acf_ngmdl_location_url', $post_id); $markers[$i]['other'] = get_field( 'acf_ngmdl_location_other', $post_id); $i++; } } } // Restore original Post Data wp_reset_postdata(); if ($markers != ''){ foreach ($markers as $marker) { $lng = $marker['lng']; $lat = $marker['lat']; $address = isset($marker['address']) ? $marker['address'] : ''; $title = isset($marker['title']) ? $marker['title'] : ''; $phone = isset($marker['phone']) ? $marker['phone'] : ''; $url = isset($marker['url']) ? $marker['url'] : ''; $other = isset($marker['other']) ? $marker['other'] : ''; $mail_to = ''; if (strpos($url,'@') !== false) { $mail_to = "mailto:"; } if ($address != '') : $marker_instances .= "
".$title."

".$address."

".$phone."

".$other."

".$url."

"; endif; } } } $return .= "
".$marker_instances."
"; echo $return; exit(); } /* * acf_ngmdl_get_terms_id_list * * @description: Get the array list of ID by category or name * @since: 1.0 * @created: 21/09/14 */ public function acf_ngmdl_get_terms_id_list($terms){ $taxonomy = 'acf_maps_category'; $slugs = array(); $array = array(); foreach ($terms as $term) { $slugs[] = get_term_by( 'slug', $term, $taxonomy, 'ARRAY_A' ); $slugs[] = get_term_by( 'name', $term, $taxonomy, 'ARRAY_A' ); } foreach ($slugs as $slug) { $array[] = $slug['term_id']; } $array = array_unique($array); return $array; } } } ?>