If I’m understanding your issue correctly, and if by ‘project title’ you mean the content of the post_title
field, then it’ll look something like this:
$post_data = array();
$my_query = new WP_Query( $whatever_your_args_are );
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post();
$post_data[] = array(
'project_title' => get_the_title(),
'latitude' => get_post_meta( get_the_ID(), 'latitude', true ),
'longitude' => get_post_meta( get_the_ID(), 'longitude', true )
);
}
}
echo json_encode( $post_data );
I changed your example just a touch so that the JSON object would have the values keyed nicely (project_title
, latitude
, longitude
) instead of the more opaque numerical keys. I’m also assuming that you’re using WP_Query
to query and loop through the posts. If not, you can replace the WP_Query
stuff with a loop over whatever content you’ve pulled from the DB.