What’s in get_sub_field(‘image’)? wp_get_attachment_image_src() parameter 1 should be the attachment id, not the attachment src, if that’s what you have.
I use the following function to get an attachment ID from an image url as as far as I know WP doesn’t have a method for this at present.
function get_attachment_id_from_src ($src) {
global $wpdb;
$reg = "/-[0-9]+x[0-9]+?.(jpg|jpeg|png|gif)$/i";
$src1 = preg_replace($reg,'',$src);
if($src1 != $src){
$ext = pathinfo($src, PATHINFO_EXTENSION);
$src = $src1 . '.' .$ext;
}
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$src'";
$id = $wpdb->get_var($query);
return $id;
}
Related Posts:
- Remove Dimension from wp_get_attachment_image
- Change wp_get_attachment_image attributes (src and srcset) on specific custom field
- How do I make a custom field choose an image?
- Extend WP Customizer to make multiple image selection possible
- Add multiple images to a page sidebar
- Display thumbnail from custom field
- Add custom field to image editor
- Display info from custom fields in all images’ HTML
- automatically set “Featured Image” the same as the og:i that is set in a custom field
- copy attachments to another post type and change attachment url
- limit amount of photos uploaded per cpt post
- Adding a custom field or metabox to the post-thumbnail widget?
- Metabox with multiple fields added by user and upload box
- Add WYSIWYG to Image Description field
- Get Meta from Custom Field of Image URL
- Add url from Custom Field as ‘Featured Image’. Code not working
- How to display multiple images in custom field
- How to add image attachment to post from a single meta key (Woocommerce)
- Exclude images uploaded via meta boxes from WordPress gallery
- How to add the image URL from an external RSS feed and insert into a custom field?
- Add new image block, set default class name and update it using Javascript
- Better way to save image in custom field
- How do I add an image upload, custom field to a WooCommerce product?
- How to use thumbnail size of image if I’m only using src to get image
- For homepage images (for small business website), is it better to use custom fields or post_thumbnail?
- Select multiple images from custom field
- Displaying page image in the footer automatically
- Get image url using image id
- Show image if author meta (profile fields) exists outside loop
- Convert attachment ID into url?
- Custom field as featured image caption
- Display a different image for each page with editor
- Image upload and path to custom field
- How to get custom image field of specific post id
- Custom field outside the loop and inside an array
- Selectively hiding or allowing thumbnails of featured images on front page
- Unable to select image with custom field
- Users uploaded image and matching an id or taxonomy
- Adding Facebook’s image and meta description retrieval capabilities to a WordPress post
- Show image depending on the number in the custom fields
- How to delete attachments associated with custom field type when post property changes? [closed]
- Use a different catalog image than the featured image
- How to add custom fields to images for image source text and URL
- Get first URL from custom field, download and set as featured image on post publish
- Change path to child of page when uploading image via custom field
- Analyze uploaded images to get colour values
- Adding thumbnails for non-image attachments
- Upload image to wordpress
- Undefined Variable (Displaying image via custom field)
- Multiple image uploader under editor?
- Get single image from custom fields made with WCK custom fields creator
- Add image custom attribute [closed]
- How to mark a image attachment as background image?
- Crop custom image size vs actual size
- Meta Query with AND & OR?
- Adding another state (spam, reject, approve) to wordpress comments?
- Filter archive.php by custom meta
- How do I search an array stored in a custom-field using WP_Query?
- Custom text-only header
- Adding Custom Text Area to WooCommerce Product
- Get multiple custom field values in a $wpdb query [duplicate]
- add meta box using function.php
- Custom image sizes for custom field media uploads
- converting custom field date format
- Image Quality Thumbnail Compression in WordPress?
- Use ‘medium’ size with catch_that_image() function
- Buddypress Add unserialized Profile Fields in Members Loop [closed]
- Custom Field returning Numerical Value for Image rather than URL
- Add Paypal Button programmatically
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- Conditionally hide or show woocommerce product variation in fontend by custom field
- custom meta box text field: how to limit to alpha or numeric only
- Accessing loop functions (e.g the_title or the_content) from post ID
- Create an Array of Specific Custom Post Meta
- Excluding Specific Fields from Profile Builder Registration Form
- How to add upload video option in wordpress for user?
- Set post to unpublished after one week depending on condition
- URL Rewrite fires when retrieving a custom value?
- Filter for post_thumbnail: link to small src and add data-attribute [duplicate]
- Efficiently sort only certain categories by custom field
- How can I do a variable for meta_query?
- How to list Category list in ACF Pro’s Select Field to choose from [closed]
- Display custom field & value correctly on page
- Copy price categories to custom field
- Use Advanced Custom Fields – replace line of code that hardcodes the tag into the template
- Advanced Custom Fields and Post Meta Fields Relation
- Else/If Statement to Display Photo Descriptions
- Filter posts by custom field (Advanced Custom Fields)
- KEY and VALUE custom field issue
- WP E-Commerce Custom Meta > Serialized array
- Saving Custom Field that includes Quotation marks
- Saving custom form data
- Echo out custom fields in comments
- Why WordPress takes time to make request to save post?
- get the post thumbnail returns the full size
- Convert all dates in field to Unix time, except those already in Unix time
- get_post_custom_values not working
- Show div based on custom meta value
- Assign class to Drop Down Selections in WooCommerce Products Custom Fields