I'm trying to get values (latitude, longitude and an image) from the WordPress database and put it into a javascript array.
Unfortunately I'm a newbie at Javascript and PHP!
Here is the code I have so far:
getdata.php:
<?php
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
?>
distance.php:
<?php
include 'getdata.php';
?>
<html>
<head>
<script type="text/javascript">
<?php $args = array( 'post_type' => 'listing', 'p' => $post_id ); ?>
values = [ <?php
$listing_marker_loop = new WP_Query( $args );
while ( $listing_marker_loop->have_posts() ) : $listing_marker_loop->the_post();
$address = get_field('location');
global $post;
// load all 'categories' terms for the post
endwhile;
?>];
alert(values[1]);
</script>
</head>
<body></body>
</html>
I'm trying to get it to give me an alert, so that I know I'm on the right track!
Can someone tell me how to make this work?