Open demitri opened 6 years ago
I'm getting the same issue. Going to try and figure out how to fix it...
Just in case anyone else hits this issue. I know it's not pretty, but here's how I solved it in my plugin in the meantime:
function get_media_fields($row)
{
if ($row["type"] == "attachment")
{
$pod = pods("media", $row["id"]);
foreach ($pod->fields() as $field)
{
$name = $field['name'];
$meta = $pod->display($name, true);
$row[$name] = $meta;
}
}
return $row;
}
function rest_request_after_callbacks( $response, $handler, $request )
{
if (strpos($request->get_route(), "/wp/v2/media") === FALSE)
return $response;
if (array_key_exists("X-WP-Total", $response->headers))
{
for ($i=0; $i < count($response->data); $i++)
{
$response->data[$i] = self::get_media_fields( $response->data[$i] );
}
}
else
$response->data = self::get_media_fields( $response->data );
return $response;
}
add_filter( 'rest_request_after_callbacks', 'rest_request_after_callbacks', 20, 3);
Hi, the issue still on. I facing this , by using @nielo method, am getting the vaules in api, however like if am posting the images with data, it's not saving ... i have to do in wp otherwise its not displaying. its been almost one year.
Issue Overview
Created a new Pod that is an extension of the 'media' type. Custom fields are returned in the API, but all values are
false
.Expected Behavior
JSON fields populated with values defined in the WordPress interface.
Current Behavior
New fields are being returned in the JSON response, but all values are
false
.Possible Solution
I don't know anything about the internals.
Steps to Reproduce (for bugs)
Media
.Pods Package Export (helpful!)
Related Issues and/or PRs
Todos
WordPress Environment