metadata

WordPress.com now supports geotagging your posts. To enable the use of geotagging, find the new Location box in your Post Editor — you’ll see a “Turn On Location Tagging” button to enable it. Because of the improvements we’ve made in handling metadata, you can now geotag posts via the REST API.

Geo metadata keys are as follows:

geo_address

(required) A human-readable description string of the location name.

geo_latitude

(required) Latitude as a signed numeric value of degrees North of the Equator.

geo_longitude

(required) Longitude as a signed numeric value of degrees East of the Greenwich Meridian.

geo_public

(internal) If a post has a geolocation set, this will be true; it will be false if that information is unset.

If the address field is empty, the post will have a private location and the latitude and longitude values will be discarded.

The following code example demonstrates the array structure for creating a new post which is geotagged.

Like this:

We’ve recently made some updates to the REST API which is available here on WordPress.com and for any Jetpack-enabled site that has the REST API module activated. The API now has full read and write support for custom post types and post metadata.

You can also query posts by metadata using the new meta_key and meta_value parameters. You can add, update, delete or retrieve a post’s metadata when creating, editing or getting a single post, using the new metadata parameter which accepts an array of metadata keys, ids, previous_values, values and operations, based on the operation you are trying to perform.

In order to enable your custom post types to work with the REST API on your Jetpack enabled sites, you will need to whitelist them using the new rest_api_allowed_post_types filter available in Jetpack, which is a simple array of the post type names that should be allowed to work with the API.

All metadata keys can be accessed and edited by users with the edit_post_meta (used for editing and viewing), add_post_meta and delete_post_meta capabilities as appropriate for each operation. We’ve also added a filter rest_api_allowed_public_metadata that allows you to specifically whitelist certain metadata keys to be accessed (but not modified) by any user (even anonymous).

Here’s a quick rundown. If the user performing the request is unauthenticated, they will not be able to add, edit or delete any metadata; they will only be able to read specifically whitelisted metadata keys.

If the user performing the request is authenticated and has the above listed capabilities, they will be able to read, add, edit or delete any metadata, even if it is not whitelisted.

In order to make it easier for you to add support for custom post types and metadata in your own plugins and themes, we’ve also added a third filter jetpack_rest_api_compat in the main Jetpack file, which allows you to load additional files where you can then add all of your REST API compatibility code, using the filters above.

Because we love bbPress, we’ve bundled support for bbPress and the REST API directly into Jetpack, so that you can read, write and edit bbPress forums, topics and replies right out of the box. You can also use this file as an example on how to bundle support in your own plugins or themes.