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?
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 9 years, 3 months ago by
donachy.
-
This reply was modified 9 years, 3 months ago by
donachy.
-
This reply was modified 9 years, 3 months ago by
donachy.
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.
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 😉
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?
Perfect!!!
a quick test seems to work!!!
Nice job, thanks