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 *remove* a parent theme page template from a child theme?
- How to disable page delete
- How to update the delete user confirmation form?
- Creating a rotating header /image slider using theme customization
- In the new Theme Customizer API, how to send a value from the front back to the admin panel?
- How do I add Post Like and Bookmark Functionality to my WordPress Site?
- How to exclude certain widget from showing up on home/front page? [duplicate]
- sanitize attachment filename
- Caption shortcodes not including caption as attribute
- Customize the WordPress Default Gallery Output
- Programmatically (PHP) get the nr. of items in the primary navigation menu
- How to create left and right menu with logo center in a custom theme?
- 1 WordPress installation with 2 pages: every page gets a separate domain
- REQUIRED: Could not find wp_link_pages. See: wp_link_pages by Theme Checker
- problem in uploading attachment to custom directory
- How to update theme from localhost to online site
- Is it necessary to use Timthumb in WordPress 2.9+?
- How to show wp.me shortlink underneath each post?
- Change admin avatar only (without Gravatar or plugin)?
- How do I change the element using a custom function?
- Is it necessary to prefix theme_mod, section id and panel id in the customizer?
- Create a custom admin panel
- Translate custom template with WPML
- How can I resolve a .htaccess internal server error setting up a WordPress multisite?
- Is it possible to add custom badges to product attributes conditionally, based on custom field?
- Product page not found if product data is set Appointment Service
- I want to embed mystream video in my wordpress site
- Current menu item highlights wrong
- Measure time in ONLY HOUR format
- How can error pages be customized
- Replace an URL with an new URL which has a “?” in it
- Child Theme – Changing Header
- remove or hide Link Relationship (XFN) form Menus tab
- Displaying Child Page’s Information
- Changing ‘Add to cart’ button text and relink for some specific products [closed]
- adding a custom time class to in theme twenty sixteen
- ‘str_replace’ and ‘strtr’ not working inside plugin
- SAving PHP in custom wordpress option field
- Does WordPress support template resources/custom fields
- Edit a custom admin page
- Remove Twenty Twelve themes responsiveness in Internet Explorer
- Change the way wordpress outputs images or image galleries
- Looking for a way to take readers to random post when clicking a link
- Cannot upload to S3 using CDN Sync Tool
- Custom Import with taxonomies
- HTML in PHP problem [closed]
- Very Simple Geo targeting
- Consolidate ‘add-to-cart’ buttons into one ‘add-all-to-cart’ button
- Update to WordPress 4.9.2, but have heavily customized theme
- Storing form data into wordpress database [closed]
- Show total sales for each products on search results page Woocommerce
- Permalink Listing WordPress