how to get array of array from post meta data in wordpress











up vote
0
down vote

favorite












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..










share|improve this question
























  • do you want it in PHP or JS?
    – Sudharshan Nair
    Nov 22 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 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 at 16:03















up vote
0
down vote

favorite












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..










share|improve this question
























  • do you want it in PHP or JS?
    – Sudharshan Nair
    Nov 22 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 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 at 16:03













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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..










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 30 at 13:06

























asked Nov 22 at 9:43









Bala

12




12












  • do you want it in PHP or JS?
    – Sudharshan Nair
    Nov 22 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 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 at 16:03


















  • do you want it in PHP or JS?
    – Sudharshan Nair
    Nov 22 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 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 at 16:03
















do you want it in PHP or JS?
– Sudharshan Nair
Nov 22 at 11:44




do you want it in PHP or JS?
– Sudharshan Nair
Nov 22 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 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 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 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 at 16:03












1 Answer
1






active

oldest

votes

















up vote
0
down vote













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>





share|improve this answer























  • 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 at 12:49












  • i have edited my code please check once and give me solution for that
    – Bala
    Nov 30 at 13:08










  • @Bala. Edited my answer. Can you print $getCord and let me know what its showing now
    – Sudharshan Nair
    Dec 3 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 at 15:01













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',
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
});


}
});














draft saved

draft discarded


















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








up vote
0
down vote













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>





share|improve this answer























  • 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 at 12:49












  • i have edited my code please check once and give me solution for that
    – Bala
    Nov 30 at 13:08










  • @Bala. Edited my answer. Can you print $getCord and let me know what its showing now
    – Sudharshan Nair
    Dec 3 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 at 15:01

















up vote
0
down vote













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>





share|improve this answer























  • 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 at 12:49












  • i have edited my code please check once and give me solution for that
    – Bala
    Nov 30 at 13:08










  • @Bala. Edited my answer. Can you print $getCord and let me know what its showing now
    – Sudharshan Nair
    Dec 3 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 at 15:01















up vote
0
down vote










up vote
0
down vote









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>





share|improve this answer














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>






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 3 at 12:38

























answered Nov 26 at 4:38









Sudharshan Nair

746114




746114












  • 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 at 12:49












  • i have edited my code please check once and give me solution for that
    – Bala
    Nov 30 at 13:08










  • @Bala. Edited my answer. Can you print $getCord and let me know what its showing now
    – Sudharshan Nair
    Dec 3 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 at 15:01




















  • 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 at 12:49












  • i have edited my code please check once and give me solution for that
    – Bala
    Nov 30 at 13:08










  • @Bala. Edited my answer. Can you print $getCord and let me know what its showing now
    – Sudharshan Nair
    Dec 3 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 at 15:01


















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 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 at 12:49














i have edited my code please check once and give me solution for that
– Bala
Nov 30 at 13:08




i have edited my code please check once and give me solution for that
– Bala
Nov 30 at 13:08












@Bala. Edited my answer. Can you print $getCord and let me know what its showing now
– Sudharshan Nair
Dec 3 at 12:39






@Bala. Edited my answer. Can you print $getCord and let me know what its showing now
– Sudharshan Nair
Dec 3 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 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 at 15:01




















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)