0

I'm using wordpress.com's public REST API to retrieve custom posts from a Wordpress installation. The JSON that's being returned is missing all the custom fields, however. The fields are definitely there and working, because I can filter on them. For example this URL:

https://public-api.wordpress.com/rest/v1/sites/swnfest.com/posts/?type=artist&meta_key=facebook&meta_value=outfitoutfitoutfit

is successfully limiting based on the facebook custom field, but that field isn't present in the response. Judging by the criteria for including custom fields in this article:

If the user performing the request is unauthenicated, he or she will not be able to add, edit or delete any metadata; will be able to read any metadata for which the key doesn’t begin with _ but will not be able to read any metadata which begins with _ unless it is whitelisted.

the field should be appearing. Is there something I'm missing, or is this a bug?

  • wordpress.com customizations are off topic here. Please ask their support. – fuxia Sep 13 '13 at 9:17
  • Please excuse my ignorance because I know nothing about Wordpress - but this isn't anything to do with wordpress.com (bar using their public API) - the site in question is a private wordpress installation. To my knowledge nothing has been customised, beyond the post type which is custom. Is that what you're referring to? – Craig Sep 15 '13 at 19:17
  • Try making an authenticated request. – Paul Schreiber Apr 30 '15 at 17:41
1

Try using the rest_api_allowed_public_metadata filter to whitelist the facebook custom field. It will then appear in the response:

add_filter( 'rest_api_allowed_public_metadata', 'jeherve_allow_fb_metadata' );
function jeherve_allow_fb_metadata() {
    // only run for REST API requests
    if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST )
        return $allowed_meta_keys;

    $allowed_meta_keys[] = 'facebook';

    return $allowed_meta_keys;
}
  • Thanks; I have similar code in place but it doesn't make any difference. I raised this with Jetpack support and they think it's a problem on their end, so I'm waiting to see what happens with that. – Craig Sep 22 '13 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.