If this is related to your other question then the custom field is attached to the post and not the attachment. You need to get the post ID of the post first then you can get the custom field. This should work.
global $wp_query;
$attachment_id = $wp_query->post->ID;
$parent_id = get_post_field('post_parent', $attachment_id);
echo get_post_meta($parent_id, 'my_custom_field', true);
Related Posts:
- Remove Dimension from wp_get_attachment_image
- explode array within shortcode
- How can I append custom data to images in the editor?
- How can I remove fields in the attachment editor?
- Saving Custom Field in Attachment Window in WordPress 3.5
- Add multiple images to a page sidebar
- How to set a default meta value for custom field
- Add custom field to image editor
- How to save custom fields for attachments
- Display info from custom fields in all images’ HTML
- copy attachments to another post type and change attachment url
- ajax delete value from custom field array
- Save attachment custom fields on front end
- Insert attachment ID in custom field from media uploader
- How can I store a file in the database in the same way WordPress and ACF do?
- Getting the ID of any image for use in functions.php
- Validate data on attachment_fields_to_save
- How do i save and retrieve custom attachment meta?
- Custom field not updating when value is empty
- how to upload a image from frontend with wp_insert_post and also update_post_meta?
- Link FROM attachment to full post and get custom fields values on attachment page?
- Attach images to posts using custom fields (just paths to images already uploaded)
- Save attachment ID instead of URL in custom field
- Shortcode for Custom Field of Media Attachment (to use with Featured Images)
- Custom field in media library not saving, selected() function not adding “selected” to select list input type
- How to delete attachments associated with custom field type when post property changes? [closed]
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- Adding thumbnails for non-image attachments
- How can I attach files without using a plugin?
- Is there a way to set default custom fields when creating a post?
- Underscores in custom fields
- Add custom field to the archive page?
- Show only posts which can be commented OR have custom meta field
- Need small coding with Custom Fields Search
- How do I make a custom field choose an image?
- get_post_meta() unserialize issue – returns boolean(false)
- Unable to get Preview of Uploaded image within a Custom Meta box
- Edit Custom Database Tables in WordPress
- How to store the value of a custom field dropdown select for post referencing?
- Change content before writing to database
- post meta data clearing on autosave
- WordPress Search Custom Meta Field Only
- Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’
- Add description text under input field for new profile fields
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- Echo values from custom field outside loop php
- How to add content at the end of posts?
- Transfer self made functions.php custom fields to Advanced Custom Fields [closed]
- Complex WP_User_Query call fails on production server
- How to query posts with certain custom meta data, and output Post data
- Custom Fields Not in Search Results
- wordpress custom fields multiple data
- How do I define post titles as images using Custom Fields?
- How to show Small Box Inside Content Area, which holds (text, images, links)?
- Sort custom field by post
- Get an advanced custom field after post publish
- Why the pagination for a query modified by pre_get_posts doesn’t mind the number & order of posts sorted & selected based on a custom date time field
- Trying to update_post_meta function
- How do i add custom fields to my themes template file?
- Custom Field to a Role?
- Pull custom fields from custom posts within a loop
- Ordering posts by custom field named “date” in backend
- How to pass page as an argument like post in WordPress?
- How to display custom fields from a plugin
- Adding “meta” info to WP site PHP function?
- WordPress Media Uploader custom Javascript not working
- Custom fields issue [closed]
- Select custom posts by meta_value and sort by a different meta value
- List custom queried terms in the edit-tags.php?taxonomy page
- Front end register with custom fields
- Display custom field from the front page on another page
- No result update a custom field using wp_schedule_event
- Is there a (sane) way to get all custom fields for a post, which do not have a leading underscore?
- custom filed from post in the side bar
- Rewrite comment form post ID on submit
- Add a custom field to my custom post type and then get posts which are before the given date in the custom field
- Move the metaboxes to the very top of post editor
- Custom User Dashboard
- Custom Fields not working properly
- Custom meta POST request fired twice when updating a post in Gutenberg
- add meta box considers the selected option as post parent
- Custom fields multiple commas separated values
- How do I display a custom field in an existing form on the front end?
- How to save array option as text and not integer?
- Extend WP_User_Query or WP_User to return all custom fields?
- Quicktag button to automatically add a custom field to a post
- Display custom fields only if it has a value
- WordPress taxonomy child image
- Create custom fields/meta data gender+country – radiobuttons and dropdown on register screen for these fields
- Add nofollow to custom field link and make domain exceptions?
- wordpress simple post multi rating with post_meta and user_meta
- Custom fields are not displaying in page with multiple loops
- Add class from custom field into widget class
- Download stuff after filling fields?
- Adding custom field to Lightbox in header only pulls current page data, not Lightbox item data
- Meta boxes not displayed, data isn’t being saved
- Custom registration form and custom field
- How can i put a custom field inside this php
- Truncating characters in Advanced Custom Fields works some places but not others?
- How to add an ACF only for parent term?