It’s possible if the appropriate meta fields have been exposed to the API with register_meta(). See https://developer.ww.wp.xz.cn/rest-api/extending-the-rest-api/modifying-responses/
When inserting a post, specify the lat/long values like you would any other meta values. Build an associative key/value array and assign it to the post’s “meta” item prior to converting the whole thing to JSON. The lat/long values will be saved as strings. Format the values in whichever way would be most useful to functions using the values. It’s not normally necessary to type cast from string back to a floating number. If it becomes an issue, both PHP and JavaScript have ways to type cast values.
Thread Starter
ngow
(@ngow)
Thanks for the response, I was using a plugin SimpleLocation, this had the register_meta() calls, but had set the ‘show_in_rest’ to false, so very easy to change to true.
Hoping the meta value and names to use is easy to sort out.
If you are unable to discern the right key names from source code, use the phpMyAdmin app to examine table records. Newly added meta data is normally found at the bottom of the postmeta table.
Thread Starter
ngow
(@ngow)
All sorted thanks for your assistance.
Correct syntax and naming, so can now set and update the post geo location data via the rest api. Javascript example below:
var post_data = {
id:o_post.id,
title:"Title",
content:"Content of the post",
categories:"1,2",
tags:"5,6,7",
meta:{
geo_latitude:"51.4411688",
geo_longitude:"-0.2746582",
geo_address:"Park",
geo_public:"1",
},
status:"publish",
};
var body_data = JSON.stringify(post_data);