Display all description with the same taxonomie in google map marker using ajax

For the moment I can not display all the descriptions related to the same taxonomies. I only display the most recent alert. my goal and to display the descriptions of all alerts related to each taxonomy.
inside the marker tooltips

function get_alerte($term) {
$alert_info = array();

$t_id = $term->term_id;
$term_count = $term->count;

$args = array(
‘post_type’ => ‘alertes’,
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘implantations’,
‘field’ => ‘id’,
‘terms’ => $t_id, // Where term_id of Term 1 is “1”.

)
));

$alertes = new WP_Query($args);

if ($term_count == 0) { /* If the implementation does not have an alert yet*/
$alert_info[‘statut’] = ‘fonctionnement’;
$alert_info[‘description’] = ”;

} else {

$terms = get_objects_in_term(get_term_by(‘slug’, ‘implantation’ )->term_id, ‘implantation’);
/* Otherwise we recover the last alert dated*/
if ($alertes->have_posts()) {
$alertes->the_post();
$alerte_id = get_the_ID();
$statut = get_post_meta($alerte_id, ‘_statut’, true);
$alert_info[‘statut’] = $statut;
$alert_info[‘date_parution’] =get_post_meta($alerte_id, ‘_intervention’, true); ;
$alert_info[‘description’] = ($statut == ‘fonctionnement’)? ” : get_the_content_feed() ;
}
}

return $alert_info;

}

/* Front.php */

function get_implantations() {

/*Table that will recover theJS */
$json_response = array();
$json_response[‘plugin_url’] = plugins_url(‘/carte-coupures-V2’);
$json_response[‘points’] = array();

/* On récupère les implantations */
$taxonomy = array(‘implantations’);
$args = array(
‘orderby’ => ‘name’,
‘order’ => ‘ASC’,
‘hide_empty’ => false,
‘exclude’ => array(),
‘exclude_tree’ => array(),
‘include’ => array(),
‘number’ => ”,
‘fields’ => ‘all’,
);

/* On parcours les implantation (terms) */
$terms = get_terms($taxonomy, $args);
if (!empty($terms)) {
foreach ($terms as $term) {
$term_id = $term->term_id;
$term_meta = get_option(“taxonomy_$term_id”);
$row_array[‘name’] = $term->name;
$row_array[‘lat’] = $term_meta[‘lat’];
$row_array[‘lng’] = $term_meta[‘lng’];

/* We recover the status and the description of the last alert */
$alert = get_alerte($term);

$row_array[‘statut’] = $alert[‘statut’];
$row_array[‘date_parution’] = $alert[‘date_parution’];
$row_array[‘description’] = $alert[‘description’];

array_push($json_response[‘points’], $row_array);
}
echo json_encode($json_response);

die();
}

}

add_action(‘wp_ajax_get_implantations’, ‘get_implantations’);
add_action(‘wp_ajax_nopriv_get_implantations’, ‘get_implantations’);

/* JS FILE */

/—————-AJAX REQUEST——————-/
var points = {};
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(“GET”, “../../wp-admin/admin-ajax.php?action=get_implantations”, false); //Version distante
//xmlhttp.open(“GET”, “../wp-admin/admin-ajax.php?action=get_implantations”, false); //Version local
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
response = JSON.parse(xmlhttp.responseText);
plugin_url = response.plugin_url;
points = response.points;

}

};
xmlhttp.send(null);

/————–MAP—————–/

/Variable for tooltip/
var infowindow;

function initialize() {
/Creation of the map/
var map = new google.maps.Map(document.getElementById(‘map-canvas’), {
center: new google.maps.LatLng(14.6500000, -61.0297823),
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 11
});

/* Tour of the JSON*/
for (var i in points) {
var implant = points[i];
var location = new google.maps.LatLng(implant.lat, implant.lng);
/* The corresponding description of the implementation status */
var description = implant[“description”];
addMarker(map, implant.name, implant.description, location, implant.statut, implant.date_parution, description);
}

}

/–Function to add the marker–/
function addMarker(map, name, description, location, statut, date_parution, message) {

/*Creation of the green pine – orange – red*/
var icon = plugin_url + “/front/assets/” + statut + “.png”;

/*icon*/
var marker = new google.maps.Marker({
position: location,
map: map,
title: name,
icon: new google.maps.MarkerImage(icon)
});

/*Content creation*/
var date = (statut !== ‘fonctionnement’ ) ? ‘ <strong class=”cc-date”>’ + date_parution+ ‘</strong> ‘ : ”,
/*We only display the btn if the implementation works*/
signalerButton = (statut == “fonctionnement”) ? ‘<a href=”/contact”>Signaler une panne</a>’ : ”,
contentString = ‘<div class=”cc-info-bulle”><h5>’ + name + ‘</h5>’ + date + ‘<p>’ + message + ‘</p>’ + signalerButton + ‘</div>’;

google.maps.event.addListener(marker, ‘click’, function () {
/*Close window open info */
if (typeof infowindow != ‘undefined’)
infowindow.close();
infowindow = new google.maps.InfoWindow({
content: contentString
});
infowindow.open(map, marker);
});

}

google.maps.event.addDomListener(window, ‘load’, initialize);
strong text

Read more here:: Display all description with the same taxonomie in google map marker using ajax

Leave a Reply

Your email address will not be published. Required fields are marked *