Function Reference: create_marker_jason_of_posts
Summary
Creates marker json using given $post object.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $map_jason
- (array) (required) Map data in json format.
- Default: None
- $add_post_in_marker_array
- (bool) (required) Displays posts in marker array when the value is true.
- Default: None
- $geodir_cat_icons
- (array) (required) Category icons array. syntax: array( ‘category name’ => ‘icon url’).
- Default: None
- $gd_marker_sizes
- (array) (required) Array of the marker icons sizes.
- Default: None
Package
GeoDirectory
Parameters
- $post
- (null|WP_Post) (required) Post object.
- Default: None
Change Log
Since: 1.0.0
1.5.0 Converts icon url to HTTPS if HTTPS is active.
1.6.1 Marker icons size added.
Filters
‘geodir_create_marker_jason_of_posts’ [Line: 107]
Source File
create_marker_jason_of_posts() is located in geodirectory-functions/map-functions/map_functions.php [Line: 51]
Source Code
function create_marker_jason_of_posts($post) { global $wpdb, $map_jason, $add_post_in_marker_array, $geodir_cat_icons, $gd_marker_sizes; if (!empty($post) && isset($post->ID) && $post->ID > 0 && (is_main_query() || $add_post_in_marker_array)) { if(isset($map_jason[$post->ID])){return null;} $srcharr = array("'", "/", "-", '"', '\\'); $replarr = array("′", "⁄", "–", "“", ''); $default_category = isset($post->default_category) ? $post->default_category : geodir_get_post_meta($post->ID,'default_category'); $geodir_cat_icons = geodir_get_term_icon(); $icon = !empty($geodir_cat_icons) && isset($geodir_cat_icons[$default_category]) ? $geodir_cat_icons[$default_category] : ''; $post_title = $post->post_title; $title = str_replace($srcharr, $replarr, $post_title); if (is_ssl()) { $icon = str_replace("http:","https:",$icon ); } if ($icon != '') { $gd_marker_sizes = empty($gd_marker_sizes) ? array() : $gd_marker_sizes; if (isset($gd_marker_sizes[$icon])) { $icon_size = $gd_marker_sizes[$icon]; } else { $icon_size = geodir_get_marker_size($icon); $gd_marker_sizes[$icon] = $icon_size; } } else { $icon_size = array('w' => 36, 'h' => 45); } $post_latitude = isset($post->post_latitude) ? $post->post_latitude : geodir_get_post_meta($post->ID,'post_latitude'); $post_longitude = isset($post->post_longitude) ? $post->post_longitude : geodir_get_post_meta($post->ID,'post_longitude'); $post_json = '{"id":"' . $post->ID . '","t": "' . $title . '","lt": "' . $post_latitude . '","ln": "' . $post_longitude . '","mk_id":"' . $post->ID . '_' . $default_category . '","i":"' . $icon . '","w":"' . $icon_size['w'] . '","h":"' . $icon_size['h'] . '"}'; /** * Filter the json data when creating output for post json marker.. * * @since 1.5.7 * @param string $post_json JSON representation of the post marker info. * @param object $post The post object. */ $post_map_json = apply_filters('geodir_create_marker_jason_of_posts',$post_json, $post); // only assign it if it has a value if($post_map_json){ $map_jason[$post->ID] = $post_map_json; } } }