Support » Plugin: REST API - Filter Fields » nice but doesn’t work with _embed param

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author svrooij

    (@svrooij)

    Hello @donachy,

    The code can be found here, if you would like to help you’re more then welcome.

    I’m not sure how to solve this. You got any ideas?

    donachy

    (@donachy)

    Hi svrooij,
    I took a look into your code and debugged a bit on my test-site
    it seems _embedded fields are not present in the
    $data after this operation $data= $data->data;
    so something happens here, of course the rest of code is not the problem.

    If I call every endpoint (i.e. wp-json/wp/v2/posts/x) with the ?_embed, without using “fields” params the data are returned
    and if i return $data in your plugin before that operation all fields are returned including _embedded

    Also noticed that seems to miss the links information in fields

    I.e. if I call a post endpoint (without _embed), for author’s field I obtain

    “author”:[{“embeddable”:true,”href”:”http:\/\/mysite\/wp-json\/wp\/v2\/users\/2″}]

    while if I filter using your plugin I obtain

    “author”:2

    So because the _embedded fields are based on _links and “embeddable” presence, I think this could be the point

    I hope this help

    • This reply was modified 3 years ago by donachy.
    • This reply was modified 3 years ago by donachy.
    • This reply was modified 3 years ago by donachy.
    Plugin Author svrooij

    (@svrooij)

    Could it be possible that a key in a php array cannot start with an underscore?
    The plugin works by array filtering, it loops through the array and sets the value in the new array if the key is in the list of fields.

    I cannot find the code for the _embedded field (e.g. I don’t know where it is added).

    Don’t have a solution for this at the moment maybe some other WordPress wizard could show me the way.

    donachy

    (@donachy)

    I really don’t know this.

    I found the code of _embedded fields in
    wp-includes/rest-api/class-wp-rest-server.php

    but I don’t understand wich is the problem

    Anyway, thanks for trying 😉

    Plugin Author svrooij

    (@svrooij)

    The problem was that I was modifying the response and then the links (and the resulting embeds) couldn’t be retrieved.

    My latest version on Github should work. Not tested very good, so not released to the plugin dir yet.

    Could you verify this solves all the problems?

    donachy

    (@donachy)

    Perfect!!!

    a quick test seems to work!!!

    Nice job, thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘nice but doesn’t work with _embed param’ is closed to new replies.