I made a shortcut to my image by adding it directly to the API response.
//Add in functions.php, this hook is for my 'regions' post type
add_action( 'rest_api_init', 'create_api_posts_meta_field' );
function create_api_posts_meta_field() {
register_rest_field( 'regions', 'group', array(
'get_callback' => 'get_post_meta_for_api',
'schema' => null,
)
);
}
//Use the post ID to query the image and add it to your payload.
function get_post_meta_for_api( $object ) {
$post_id = $object['id'];
$post_meta = get_post_meta( $post_id );
$post_image = get_post_thumbnail_id( $post_id );
$post_meta["group_image"] = wp_get_attachment_image_src($post_image)[0];
//var_dump(wp_get_attachment_image($post_image)); die();
//Different image codex return different values, narrow in on what you want
return $post_meta;
}
Related Posts:
- Featured Image Inherited from Parent Page
- Adding Images into API
- Check if parent post is sticky on attachment page?
- upload image only
- How can I specify the width and height of the Featured Image in TwentyTwelve theme?
- Using lower resolution/size images for thumbnails on posts index
- How do I change the size of the feature picture of a single post?
- Media Library it doesn’t show any of the uploaded images after updating wordpress 6.6.2
- Add class name to post thumbnail
- Delete original image – keep thumbnail?
- the_post_thumbnail responsive srcset not populating with custom image size
- Set custom name for generated thumbnails
- How to add multiple image sizes of the same size with add_image_size
- change set_post_thumbnail_size according to post type admin page
- Can’t extract and set SVG dimensions
- Getting Thumbnail Path rather than Image Tag
- How to crop thumbnail height to auto with set width
- Image uploader with “Set Featured Image” link on front end
- adding an id to the_post_thumbnail
- How can I display my featured image correctly inside my single posts?
- Featured image upload finished hook
- Is there a hook / action that is triggered when adding or removing a post thumbnail?
- get_pages – Display child then grandchild pages
- How to replace the_post_thumbnail template tag and show the first inside the post image instead
- Resizing Images to lower Disk Space Using Plugins
- Set (featured) thumbnail for post?
- How to make thumbnail images click into blog posts
- display WP image posts in Bootstrap 4 modal
- Customising the size of images served in Visual Composer elements [closed]
- How to scale up post thumbnails/featured image?
- Get Ancestor featured image
- Upload 3 different featured image sizes to WordPress
- Change size of featured image in Edit Post screen
- Thumbnail and Featured Image With Fixed Sizes?
- the_post_thumbnail ignores size parameter
- How can I cache WordPress Rest API Response
- Is there a way to change a post’s thumbnail image(s)?
- Confused with the loop and repeating things
- WordPress thumbnail settings change
- Using concatenate with WordPress Thumbnail
- Looking for Add Title Tag on Feature Images on WP
- Is it possible to nest get_previous_post()?
- Why does wp_remote_post returns an empty body response on certain endpoints?
- Notice: Trying to get property of non-object when trying to get thumbnail URL
- How to set an equal image size for a Fallback Image as used for the Featured Image(dynamicly)
- How can I see where in my themes and plugins certain image sizes are used?
- How do I remove featured images and captions from a wordpress RSS feed?
- get_the_post_thumbnail ignores my default thumbnail size [closed]
- Remove the link to a featured image if and only if it’s not a gif
- How to query posts with featured images
- hrecipe microformat tag to “featured image”
- Server B handling add_image_size() differently than Server A
- the_title() is not displaying over the_thumbnail
- Show posts image attachments
- Choose to Display Post Thumbnail?
- How do I make images appear in the beside blog post summaries?
- Featured Image meta box shows at the bottom?
- How to get featured image thumbnail to open larger version in attachment page?
- How To Use YouTube Url Stored In Custom Field To Get Video Image and Set it As Featured Image
- Display post thumbnail in foreach loop
- Add image size array to a portfolio thumbnail in combination with Masonry Jquery Plugin
- Define width of featured image thumbnails, but also make responsive?
- Add title to image post
- How to attach images that I “insert from url” into the post?
- If no featured image, add one of the default images into DB
- the_post_thumbnail(‘medium’) still gives thumbnail-size img
- My Gallery Photos are showing in the post’s excerpts
- the_post_thumbnail not resizing
- How to add featured images to posts from a category
- How do you code a featured image into an XML as a jpg link, instead of using a data-id number?
- Change featured image when changing viewport
- Adding guiding text to the ‘Featured Image’-box in the backend
- Thumbnails regenerate wp_generate_attachment_metadata
- Using the_post_thumbnail do not rollback to original image if specified thumbnail does not exist
- Get author image from corresponding article in thumbnail
- Missing image size
- How do I filter Child Posts by Parent Post ID for Custom Post types in WordPress REST API response?
- water mark on featured post image in wordpress
- Making a ‘featured image’ become the image for a full banner (top of page) image in a blog post?
- How to change text of Remove featured image
- Add space under featured image in singel post
- Genereate widescreen featured images in different sizes
- set_post_thumbnail() shows Unattached on backend under Media
- How to get the URL of a each custom image size of a featured image
- Recent posts show thumbnail
- Add Featured Image from Existing wp-content folder
- Featured Images missing on migrated site
- Pointing Existing featured images to s3 bucket
- Displaying All Parent Pages as Featured Images
- Featured Images not appearing
- Editing featured image
- WordPress save thumbnail but don’t show it [closed]
- Get all images from posts with maximum number and without featured image
- Display featured image as post thumbnail
- Scan for first image in post and display it [duplicate]
- Change featured thumbnail based on screen size
- Show a featured image with “Link” Post Type?
- Send PUT remote request with BuddyPress checkbox
- How to display featured image caption only if exists?
- Error 400 Invalid “products[1].productId” Kinguin [closed]