0

Im hoping somebody can help with this. I am displaying a google map on a product page on my wordpress site. I have used Advanced custom fields to get a POSTCODE for the store location. I can output this to the product page with the following:

<?php $postCode = get_field('venu_postcode'); echo $postCode; ?>

But now I can not figure out how to get this value and use it in the Javascript to generate the map based on the postcode(variable). The code below is part of the javascript where the postcode should be.

var address = postCode;

If I type in

var address = 'an actual postcode';

Then the map works perfectly.

I have tried using

var postCode = "<?php Print($postCode); ?>";

to see if I could use the php variable in the javascript but have had no luck.

I keep getting the following error: Geocode was not successful for the following reason: ZERO_RESULTS

Can anybody help?

1 Answer 1

2

Print with a capital P isn't a function, you should use echo anyway.

var postCode = "<?php echo $postCode; ?>";
Sign up to request clarification or add additional context in comments.

1 Comment

this helped me fix the problem thank you! I was so sure that I was using the javascript variable incorrectly that I didnt even see the mistake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.