Hi @bakersfielddba,
Featured images are stored differently than most post meta fields. The easiest thing to do is to look for the "wp:attachment"
value. These should be automatically returned as part of the _links
array (via the WP REST API’s self discovery feature).
The featured image’s ID is also stored as post meta with the key _thumbnail_id
but these are disabled by default from the REST API. If you can’t use the attachment URL from the _links
array I can try to find out whether it’s possible to expose protected meta keys.
Let me know,
Kevin.
The issue I been running it’s the image ID it’s saved underneath in _directory_image_gallery but it’s not showing up in the API. How can have it to show in the API?
Hi @bakersfielddba,
Try this filter function:
add_filter( 'wp_rest_api_controller_exclude_hidden_meta_keys_post_types', 'yikes_include_protected_properties_in_rest_api', 10, 1 );
function yikes_include_protected_properties_in_rest_api( $cpt_array ) {
$cpt_array[] = '{your_cpt_name_here}';
return $cpt_array;
}
Edit: make sure to replace {your_cpt_name_here}
with your custom post type slug.
Are you familiar with adding filter functions?
Let me know,
Kevin.
You add it to the function.php correct? sorry for bugging you about it
It’s not working out for me
After adding that function are you able to see (and turn on) your meta field on the admin side in the Rest Controller’s settings page? The meta field won’t be immediately visible in the API until it’s turned on.
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
Side note to bakersfielddba, please do not post email addresses in these forums again.
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
Also please start a support forum topic for your issue.
https://wordpress.org/support/plugin/wp-rest-api-controller/#new-post
Using the reviews for support isn’t really appropriate.