In the filter, you will need to find the post parent of $post, get the value of the custom field of parent post and then add that value to $post['post_excerpt'] (where the caption is stored):
add_filter('attachment_fields_to_save', 'wpse_insert_custom_caption', 10, 2);
function insert_custom_default_caption($post, $attachment) {
//Check if the $post is attached to a parent post
if( $post->post_parent ) {
//Custom field of the attachment's parent post
$custom_caption = get_post_meta( $post->post_parent, 'parent_custom_field', true );
//captions are saved as the post_excerpt
if ( !empty $custom_caption ) ) {
$previous_caption = $post['post_excerpt'];
$post['post_excerpt'] = $previous_caption.$custom_caption;
}
}
return $post;
}
Related Posts:
- Why doesn’t WP_Image_Editor save images using the Filesystem API?
- Is there a plugin to make attaching images easier?
- Managing Images for a WordPress Blog: Picasa or Flickr?
- Automatically wrap post image in div
- Custom image size not selectable in uploader
- Retrieving and Storing Images Linked from Other Domains on Local Server?
- Customizer image control default value showing in customizer but not on frontend
- Importing media medium setting image gallery / image attachments
- Extract & Display the REAL first image attached to a post – extend the_post_thumbnail()
- Add filename to attachment page url
- How To Add buttons to the toolbar which appears in TinyMce when you click over images
- Image Editor does not affect custom sizes!
- How to display post title & excerpt when mouse hovers on an image?
- Is there a way to dynamically get to your uploads folder?
- Gallery IDS and Captions: hide/show on a per ID basis
- Using Fullscreenr with a wordpress blog – weird bug
- Get Image from Media Library with the Title
- Get Custom Logo Alt Text
- Using custom image resizing script in a page
- Background image not appearing
- Best way to allow overwriting images shipped with the plugin?
- NextGEN Gallery – open all images on page in fancybox [closed]
- Featured Image If Else Condition
- If custom image header does not exist display text header
- Is there a possiblity to replace profile image gravatar with custom user images
- Custom theme – how to link the image without posting it
- Trying to set specific image dimensions and crop with ACF
- Customizing the gallery of the post correctly
- Personalized Gallery what are my options?
- adding fade on mouseover to images
- Lightbox not showing image caption
- WordPress 5: including larger thumbnail image sizes in srcset than I have set
- POST 429 Error when trying to place more than 20 images into post at once
- How to add the option to choose between sizes for featured image within post editor?
- Creating custom setting in add media popup
- Upload image without resizing but insert in post with resizing
- Bio comes up when the visitor clicks on a picture
- Adding images to anchors in the list created and fetched with wp_nav_menu
- Change default “Apply Changes To” radio option when editing images
- WP_Customize_Image_Control and selecting from library?
- Adding thumbnails for non-image attachments
- featured images – custom links
- Get a different size of Image thumbnail while working with custom metabox
- Custom image sizes ignored in WP 3.5
- Edit image alignment in WordPress twentysixteen child theme on attachment page [closed]
- Set custom banner image size with wp_customize
- How to search for replacement titles and contents, excluding image URLs
- Custom Search on media files PDF images pages posts
- How to: Easily Move a WordPress Install from Development to Production?
- How to put logs in WordPress
- Pitfalls when Distributing Plugins that Access SOAP Web Services?
- WordPress 3 MU for a development/stage/production site
- How to best setup for development for a two person bi-coastal team?
- Change Default Image HTML
- How to extend a class in WordPress?
- Create a customizable child theme
- Many users with strange names register, but don’t leave comments. Should I be afraid?
- Tag description doesn’t show hyperlink
- Is there a way to rename “themes” directory name?
- Custom query with DECIMAL(5,2)
- How to remove tag cloud from taxonomy admin edit page?
- Post Thumbnail help
- Unable to display custom fields on WooCommerce product pages
- Make blog secret during design construction
- How to add “Read More…” link in twentytwenty
- How to remove the search fields in Twentytwelve
- Understrap child theme JS not working in custom-javascript.js file
- Resizing of a header/div in a website through css in wordpress [closed]
- Login/Logout Session Sharing – Multiple WordPress Installations
- Hide text if not homepage
- Static Front Page settings – distinguish between Front page and Post page
- How to format text of site subtitle
- Lost password and back to blog in same line
- Undefined variable: user_id in get_user_meta
- WordPress broken after domain name change
- Daylight Saving Time adjustment
- How to Restore Deleted Post Not in Trash
- Display content of metabox if filled in
- User profile Pick a premade Design/theme
- Recent activity query WordPress
- Can we set a redirection with dynamic content in url?
- website is not loading home page (moving from one server to another server)
- How to remove (…) from the post tilte on homepage?
- Swap home page based on user role, Elementor layout breaking
- Customized Blog/Latest Posts Page
- Password Protection issue
- Get site ID from attachment url?
- how to edit or remove the dashboard footer message [duplicate]
- How to automatically pull an information from a form field onto an other page?
- How to create a custom menu for specific user
- How to submit form data in the same page in WordPress without reloading the page?
- Translate site in own text-language [closed]
- How to work around the bug which prevents custom menus from being deleted?
- Create a folder if it doesn’t already exist
- How to remove the tagline from the HTML ?
- Custom table or form
- How I can add blog in my magento site?
- Adding Telescope / Meteor App to existing WordPress site
- Add custom information in editor summary
- A Voting system for a pageants