Skip to content

Instantly share code, notes, and snippets.

@DylanCodeCabin
Created May 10, 2021 06:05
Show Gist options
  • Save DylanCodeCabin/0df00f5831705c048d404cfd8d1d55bc to your computer and use it in GitHub Desktop.
Save DylanCodeCabin/0df00f5831705c048d404cfd8d1d55bc to your computer and use it in GitHub Desktop.
/**
* The following script allows custom field to be used as part of get variable filtering
*
* Create a custom field called 'id', set it to visible in info-window, and ensure your marker has the relevant field filled with a number
*
* Once done, add thos script and append your variable as ?custom_id=1
*/
jQuery(function($){
$(document.body).on('markersplaced.wpgmza', function(){
var custom_id = WPGMZA.getQueryParamValue("custom_id");
if(custom_id){
var temp_markers = WPGMZA.maps[0].markers;
var marker_found = false;
for(var i in temp_markers){
var tmp = temp_markers[i];
if(tmp.custom_field_data.length > 0){
var fields = tmp.custom_field_data;
for(var fi in fields){
var field = fields[fi];
if(marker_found === false){
if(field.name === "id" && parseInt(custom_id) === parseInt(field.value)){
marker_found = tmp;
}
}
}
} else {
console.log("WPMGZA Custom Field: No data found, remember to mark the field as visible in info-window for data to be available");
}
}
if(marker_found !== false){
marker_found.openInfoWindow();
} else {
console.log("WPGMZA Custom Field: We could not find a marker with custom id '" + custom_id + "' - Or Custom field is not defined as 'id' and visible in info-window");
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment