First of all I get all the values from a php array:
<?php
$user_id = get_current_user_id();
$userPostsInternal = get_user_meta( $user_id, 'save_post_internal', TRUE );
$userPostsExternal = get_user_meta( $user_id, 'save_post_external', TRUE )
?>
I then get those arrays and convert them in a JS array
var savedInternal = "<?php echo $userPostsInternal; ?>";
var savedExternal = "<?php echo $userPostsExternal; ?>";
savedInternal = savedInternal.split(',');
savedExternal = savedExternal.split(',');
I then need to check if current id value is in the js array and proceed accordingly:
if($.inArray(this.id, savedInternal) !== -1) {
console.log("yes");
} else {
console.log("no");
}
This is happening on a mouse over an element, if I place the following the id is correct, so it isn't about this.id
console.log(this.id);
I get 128545 and it is correct.
Full code:
google.maps.event.addListener(circle, 'mouseover', function(e) {
<?php
$user_id = get_current_user_id();
$userPostsInternal = get_user_meta( $user_id, 'save_post_internal', TRUE );
$userPostsExternal = get_user_meta( $user_id, 'save_post_external', TRUE )
?>
var savedInternal = "<?php echo $userPostsInternal; ?>";
var savedExternal = "<?php echo $userPostsExternal; ?>";
savedInternal = savedInternal.split(',');
savedExternal = savedExternal.split(',');
$("#timeSearch").removeClass("fadeIn").addClass("fadeOut");
$(".infoBox").removeClass("fadeOut").addClass("fadeIn");
if(this.currSite == "curr" ) {
var linkGo = this.linkToPost;
var whatSite = this.currSite;
if($.inArray(this.id, savedInternal) !== -1) {
var contentString = '<div class="row infoBox"><div class="col"><p>' + this.site + '</p><hr><h5>'+this.title+'</h5><hr><p><button data-whatSite="'+whatSite+'" data-id="'+this.id+'" type="button" class="btn-site btn btn btn-outline-dark btn-block">Già nella box</button></p><hr><a class="d-block margin-top-20 btn btn-outline-dark btn-block" href="'+linkGo+'">Vedi contenuto</a></div></div>';
} else {
var contentString = '<div class="row infoBox"><div class="col"><p>' + this.site + '</p><hr><h5>'+this.title+'</h5><hr><p><button data-whatSite="'+whatSite+'" data-id="'+this.id+'" type="button" class="btn-site btn btn btn-dark btn-block">Salva nella box</button></p><hr><a class="d-block margin-top-20 btn btn-outline-dark btn-block" href="'+linkGo+'">Vedi contenuto</a></div></div>';
}
} else {
var linkGo = linkExternal+this.linkToPost;
var whatSite = this.currSite;
if($.inArray(this.id, savedExternal) !== -1) {
var contentString = '<div class="row infoBox"><div class="col"><p>' + this.site + '</p><hr><h5>'+this.title+'</h5><hr><p><button data-whatSite="'+whatSite+'" data-id="'+this.id+'" type="button" class="btn-site btn btn btn-outline-dark btn-block">Già nella box</button></p><hr><a class="d-block margin-top-20 btn btn-outline-dark btn-block" href="'+linkGo+'">Vedi contenuto</a></div></div>';
} else {
var contentString = '<div class="row infoBox"><div class="col"><p>' + this.site + '</p><hr><h5>'+this.title+'</h5><hr><p><button data-whatSite="'+whatSite+'" data-id="'+this.id+'" type="button" class="btn-site btn btn btn-dark btn-block">Salva nella box</button></p><hr><a class="d-block margin-top-20 btn btn-outline-dark btn-block" href="'+linkGo+'">Vedi contenuto</a></div></div>';
}
}
infoWindow = new google.maps.InfoWindow({content: contentString});
infoWindow.setPosition(this.getCenter());
infoWindow.open(map);
btnBoxSave(infoWindow, whatSite);
});
$.inArrayuses strict comparison, make surethis.idis the same type as the values in the arrays.console.log(savedInternal);I get nothing yet if I place the whole array bit before the hover states in gmaps, I get the correct values$.inArray(this.id.toString(), savedInternal), do the same for the other check.