how to get array of array from post meta data in wordpress
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I want to get property locations from post meta data fields and display it on map dynamically,in Below code i took static locations.how to get these values ['Cronulla Beach', -34.028249, 151.157507, 3] dynamically.
<script type="text/javascript">
var locations = [
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.923036,151.28747820854187),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1],locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
i want to get those locations from post meta data fields.any help appreciated..
arrays wordpress var
add a comment |
I want to get property locations from post meta data fields and display it on map dynamically,in Below code i took static locations.how to get these values ['Cronulla Beach', -34.028249, 151.157507, 3] dynamically.
<script type="text/javascript">
var locations = [
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.923036,151.28747820854187),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1],locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
i want to get those locations from post meta data fields.any help appreciated..
arrays wordpress var
do you want it in PHP or JS?
– Sudharshan Nair
Nov 22 '18 at 11:44
i am doing this in wordpress template .i want to get that coordinates data from meta data of wordpress post. is there any way to get that.
– Bala
Nov 25 '18 at 7:38
get_post_meta(get_the_ID(),'addr_coordiates', true); i used this previously to get post data .how to get all post meta data values from all posts as an array
– Bala
Nov 25 '18 at 16:03
add a comment |
I want to get property locations from post meta data fields and display it on map dynamically,in Below code i took static locations.how to get these values ['Cronulla Beach', -34.028249, 151.157507, 3] dynamically.
<script type="text/javascript">
var locations = [
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.923036,151.28747820854187),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1],locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
i want to get those locations from post meta data fields.any help appreciated..
arrays wordpress var
I want to get property locations from post meta data fields and display it on map dynamically,in Below code i took static locations.how to get these values ['Cronulla Beach', -34.028249, 151.157507, 3] dynamically.
<script type="text/javascript">
var locations = [
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.923036,151.28747820854187),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1],locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
i want to get those locations from post meta data fields.any help appreciated..
arrays wordpress var
arrays wordpress var
edited Nov 30 '18 at 13:06
Bala
asked Nov 22 '18 at 9:43
BalaBala
87
87
do you want it in PHP or JS?
– Sudharshan Nair
Nov 22 '18 at 11:44
i am doing this in wordpress template .i want to get that coordinates data from meta data of wordpress post. is there any way to get that.
– Bala
Nov 25 '18 at 7:38
get_post_meta(get_the_ID(),'addr_coordiates', true); i used this previously to get post data .how to get all post meta data values from all posts as an array
– Bala
Nov 25 '18 at 16:03
add a comment |
do you want it in PHP or JS?
– Sudharshan Nair
Nov 22 '18 at 11:44
i am doing this in wordpress template .i want to get that coordinates data from meta data of wordpress post. is there any way to get that.
– Bala
Nov 25 '18 at 7:38
get_post_meta(get_the_ID(),'addr_coordiates', true); i used this previously to get post data .how to get all post meta data values from all posts as an array
– Bala
Nov 25 '18 at 16:03
do you want it in PHP or JS?
– Sudharshan Nair
Nov 22 '18 at 11:44
do you want it in PHP or JS?
– Sudharshan Nair
Nov 22 '18 at 11:44
i am doing this in wordpress template .i want to get that coordinates data from meta data of wordpress post. is there any way to get that.
– Bala
Nov 25 '18 at 7:38
i am doing this in wordpress template .i want to get that coordinates data from meta data of wordpress post. is there any way to get that.
– Bala
Nov 25 '18 at 7:38
get_post_meta(get_the_ID(),'addr_coordiates', true); i used this previously to get post data .how to get all post meta data values from all posts as an array
– Bala
Nov 25 '18 at 16:03
get_post_meta(get_the_ID(),'addr_coordiates', true); i used this previously to get post data .how to get all post meta data values from all posts as an array
– Bala
Nov 25 '18 at 16:03
add a comment |
1 Answer
1
active
oldest
votes
Add posts array with you desired arguments and collect all the coordinates.
$allPosts = get_posts( array(
'posts_per_page' => 20
));
$getCord = ;
if ( $allPosts ) {
foreach ( $allPosts as $post ) :
$getCord = get_post_meta($post->ID,'addr_coordiates', true);
endforeach;
wp_reset_postdata();
}
In Javascript:
<script>
var locations = <?php echo json_encode($getCord);?>
</script>
as your suggestion i added code but coordinates are not getting by using echo i return values it is showing as ArrayArray ,by using index getting individual values..please help me out at any cost i have to finish this task..please check below code in place of var locations i want dynamic values
– Bala
Nov 30 '18 at 12:49
i have edited my code please check once and give me solution for that
– Bala
Nov 30 '18 at 13:08
@Bala. Edited my answer. Can you print$getCord
and let me know what its showing now
– Sudharshan Nair
Dec 3 '18 at 12:39
in alert getting coordinates as an array [34.028249, 151.157507,34.0282849, 123.157507] like this how to get latitude,langitude as array please check my code oncevar locations = <?php echo json_encode($getCord);?>; alert(locations); var map = new google.maps.Map(document.getElementById('map'), { }); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i]), map: map}); in place of position not getting coordinates,if give static values marker is showing.
– Bala
Dec 4 '18 at 15:01
getting array as [ -34.028249, 151.157507, -34.028249, 151.157507, -34.028249, 151.157507,],i want to split 2 coordinates
– Bala
Dec 26 '18 at 11:12
|
show 5 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427962%2fhow-to-get-array-of-array-from-post-meta-data-in-wordpress%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add posts array with you desired arguments and collect all the coordinates.
$allPosts = get_posts( array(
'posts_per_page' => 20
));
$getCord = ;
if ( $allPosts ) {
foreach ( $allPosts as $post ) :
$getCord = get_post_meta($post->ID,'addr_coordiates', true);
endforeach;
wp_reset_postdata();
}
In Javascript:
<script>
var locations = <?php echo json_encode($getCord);?>
</script>
as your suggestion i added code but coordinates are not getting by using echo i return values it is showing as ArrayArray ,by using index getting individual values..please help me out at any cost i have to finish this task..please check below code in place of var locations i want dynamic values
– Bala
Nov 30 '18 at 12:49
i have edited my code please check once and give me solution for that
– Bala
Nov 30 '18 at 13:08
@Bala. Edited my answer. Can you print$getCord
and let me know what its showing now
– Sudharshan Nair
Dec 3 '18 at 12:39
in alert getting coordinates as an array [34.028249, 151.157507,34.0282849, 123.157507] like this how to get latitude,langitude as array please check my code oncevar locations = <?php echo json_encode($getCord);?>; alert(locations); var map = new google.maps.Map(document.getElementById('map'), { }); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i]), map: map}); in place of position not getting coordinates,if give static values marker is showing.
– Bala
Dec 4 '18 at 15:01
getting array as [ -34.028249, 151.157507, -34.028249, 151.157507, -34.028249, 151.157507,],i want to split 2 coordinates
– Bala
Dec 26 '18 at 11:12
|
show 5 more comments
Add posts array with you desired arguments and collect all the coordinates.
$allPosts = get_posts( array(
'posts_per_page' => 20
));
$getCord = ;
if ( $allPosts ) {
foreach ( $allPosts as $post ) :
$getCord = get_post_meta($post->ID,'addr_coordiates', true);
endforeach;
wp_reset_postdata();
}
In Javascript:
<script>
var locations = <?php echo json_encode($getCord);?>
</script>
as your suggestion i added code but coordinates are not getting by using echo i return values it is showing as ArrayArray ,by using index getting individual values..please help me out at any cost i have to finish this task..please check below code in place of var locations i want dynamic values
– Bala
Nov 30 '18 at 12:49
i have edited my code please check once and give me solution for that
– Bala
Nov 30 '18 at 13:08
@Bala. Edited my answer. Can you print$getCord
and let me know what its showing now
– Sudharshan Nair
Dec 3 '18 at 12:39
in alert getting coordinates as an array [34.028249, 151.157507,34.0282849, 123.157507] like this how to get latitude,langitude as array please check my code oncevar locations = <?php echo json_encode($getCord);?>; alert(locations); var map = new google.maps.Map(document.getElementById('map'), { }); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i]), map: map}); in place of position not getting coordinates,if give static values marker is showing.
– Bala
Dec 4 '18 at 15:01
getting array as [ -34.028249, 151.157507, -34.028249, 151.157507, -34.028249, 151.157507,],i want to split 2 coordinates
– Bala
Dec 26 '18 at 11:12
|
show 5 more comments
Add posts array with you desired arguments and collect all the coordinates.
$allPosts = get_posts( array(
'posts_per_page' => 20
));
$getCord = ;
if ( $allPosts ) {
foreach ( $allPosts as $post ) :
$getCord = get_post_meta($post->ID,'addr_coordiates', true);
endforeach;
wp_reset_postdata();
}
In Javascript:
<script>
var locations = <?php echo json_encode($getCord);?>
</script>
Add posts array with you desired arguments and collect all the coordinates.
$allPosts = get_posts( array(
'posts_per_page' => 20
));
$getCord = ;
if ( $allPosts ) {
foreach ( $allPosts as $post ) :
$getCord = get_post_meta($post->ID,'addr_coordiates', true);
endforeach;
wp_reset_postdata();
}
In Javascript:
<script>
var locations = <?php echo json_encode($getCord);?>
</script>
edited Dec 3 '18 at 12:38
answered Nov 26 '18 at 4:38
Sudharshan NairSudharshan Nair
803216
803216
as your suggestion i added code but coordinates are not getting by using echo i return values it is showing as ArrayArray ,by using index getting individual values..please help me out at any cost i have to finish this task..please check below code in place of var locations i want dynamic values
– Bala
Nov 30 '18 at 12:49
i have edited my code please check once and give me solution for that
– Bala
Nov 30 '18 at 13:08
@Bala. Edited my answer. Can you print$getCord
and let me know what its showing now
– Sudharshan Nair
Dec 3 '18 at 12:39
in alert getting coordinates as an array [34.028249, 151.157507,34.0282849, 123.157507] like this how to get latitude,langitude as array please check my code oncevar locations = <?php echo json_encode($getCord);?>; alert(locations); var map = new google.maps.Map(document.getElementById('map'), { }); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i]), map: map}); in place of position not getting coordinates,if give static values marker is showing.
– Bala
Dec 4 '18 at 15:01
getting array as [ -34.028249, 151.157507, -34.028249, 151.157507, -34.028249, 151.157507,],i want to split 2 coordinates
– Bala
Dec 26 '18 at 11:12
|
show 5 more comments
as your suggestion i added code but coordinates are not getting by using echo i return values it is showing as ArrayArray ,by using index getting individual values..please help me out at any cost i have to finish this task..please check below code in place of var locations i want dynamic values
– Bala
Nov 30 '18 at 12:49
i have edited my code please check once and give me solution for that
– Bala
Nov 30 '18 at 13:08
@Bala. Edited my answer. Can you print$getCord
and let me know what its showing now
– Sudharshan Nair
Dec 3 '18 at 12:39
in alert getting coordinates as an array [34.028249, 151.157507,34.0282849, 123.157507] like this how to get latitude,langitude as array please check my code oncevar locations = <?php echo json_encode($getCord);?>; alert(locations); var map = new google.maps.Map(document.getElementById('map'), { }); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i]), map: map}); in place of position not getting coordinates,if give static values marker is showing.
– Bala
Dec 4 '18 at 15:01
getting array as [ -34.028249, 151.157507, -34.028249, 151.157507, -34.028249, 151.157507,],i want to split 2 coordinates
– Bala
Dec 26 '18 at 11:12
as your suggestion i added code but coordinates are not getting by using echo i return values it is showing as ArrayArray ,by using index getting individual values..please help me out at any cost i have to finish this task..please check below code in place of var locations i want dynamic values
– Bala
Nov 30 '18 at 12:49
as your suggestion i added code but coordinates are not getting by using echo i return values it is showing as ArrayArray ,by using index getting individual values..please help me out at any cost i have to finish this task..please check below code in place of var locations i want dynamic values
– Bala
Nov 30 '18 at 12:49
i have edited my code please check once and give me solution for that
– Bala
Nov 30 '18 at 13:08
i have edited my code please check once and give me solution for that
– Bala
Nov 30 '18 at 13:08
@Bala. Edited my answer. Can you print
$getCord
and let me know what its showing now– Sudharshan Nair
Dec 3 '18 at 12:39
@Bala. Edited my answer. Can you print
$getCord
and let me know what its showing now– Sudharshan Nair
Dec 3 '18 at 12:39
in alert getting coordinates as an array [34.028249, 151.157507,34.0282849, 123.157507] like this how to get latitude,langitude as array please check my code oncevar locations = <?php echo json_encode($getCord);?>; alert(locations); var map = new google.maps.Map(document.getElementById('map'), { }); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i]), map: map}); in place of position not getting coordinates,if give static values marker is showing.
– Bala
Dec 4 '18 at 15:01
in alert getting coordinates as an array [34.028249, 151.157507,34.0282849, 123.157507] like this how to get latitude,langitude as array please check my code oncevar locations = <?php echo json_encode($getCord);?>; alert(locations); var map = new google.maps.Map(document.getElementById('map'), { }); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i]), map: map}); in place of position not getting coordinates,if give static values marker is showing.
– Bala
Dec 4 '18 at 15:01
getting array as [ -34.028249, 151.157507, -34.028249, 151.157507, -34.028249, 151.157507,],i want to split 2 coordinates
– Bala
Dec 26 '18 at 11:12
getting array as [ -34.028249, 151.157507, -34.028249, 151.157507, -34.028249, 151.157507,],i want to split 2 coordinates
– Bala
Dec 26 '18 at 11:12
|
show 5 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427962%2fhow-to-get-array-of-array-from-post-meta-data-in-wordpress%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do you want it in PHP or JS?
– Sudharshan Nair
Nov 22 '18 at 11:44
i am doing this in wordpress template .i want to get that coordinates data from meta data of wordpress post. is there any way to get that.
– Bala
Nov 25 '18 at 7:38
get_post_meta(get_the_ID(),'addr_coordiates', true); i used this previously to get post data .how to get all post meta data values from all posts as an array
– Bala
Nov 25 '18 at 16:03