Home › Forums › General Issues › Custom field in JS map
Hi everyone,
I have a js google map which links markers to wordpress post permalinks and I’d like to replace permalinks with another link written in a custom field.
Is it possible?
This is the code
if ( ! _item.location )
return;
if ( $.isArray( _item.location ) && _item.location[0] && _item.location[1] ) {
$map.gmap( ‘addMarker’, {
‘position’ : new google.maps.LatLng( _item.location[0], _item.location[1] ),
‘bounds’ : jobifyMapSettings.center.long && ( jobifyMapSettings.zoom != ‘auto’ ) ? false : true,
‘animation’ : google.maps.Animation.DROP,
‘title’ : _item.title,
‘tooltip’ : false
}, function(map, marker) {
new Tooltip({
marker : marker,
content : _item.title,
cssClass : ‘map-tooltip’
});
}).click(function(event, map) {
window.location = _item.permalink;
});
} else {
convertAddress( _item.location, function( latlong ) {
$map.gmap( ‘addMarker’, {
‘position’ : latlong,
‘bounds’ : jobifyMapSettings.center.long && ( jobifyMapSettings.zoom != ‘auto’ ) ? false : true,
‘animation’ : google.maps.Animation.DROP,
‘title’ : _item.title,
‘tooltip’ : false
}, function(map, marker) {
new Tooltip({
marker : marker,
content : _item.title,
cssClass : ‘map-tooltip’
});
}).click(function(event, map) {
window.location = _item.permalink;
});
}, _item );
}
________
Thank you in advance
Francesco
Your code shows a small snapshot of the entire picture. It looks like all the market data comes from a variable called _item
.
I am not sure how this variable exists, perhaps it is within a loop of items
?
On top of that, I don’t know where _item
gets any of it’s data. Perhaps from a JSON feed? Perhaps from elements in the DOM using data-
tags?
You will need to find where the item data comes from, and find a way to customize the PHP which renders it.
Due to the nature of this question, I won’t be able to provide much help, but perhaps another web developer could provide some freelance services to you?
Thanks
E
Hi Elliot,
I kindly thank you for your answer and availability. I solved the problem myself, variable was in a php file through JSON function.
You are a master!
Thank you
Best
Francesco
The topic ‘Custom field in JS map’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.