this should work but you overwrite the values for existing objects.
to add default values only for new objects try that :
$postType = "tender";
add_action( 'save_post_' . $postType, function ($post_ID, \WP_Post $tender, $update) {
if (!$update) {
// default value for new object
// Add the meta data you want the custom post type to have
$tender_meta_data = [
'briefing',
'closing',
'rfirfqnumber',
'download',
];
foreach ( $tender_meta_data as $meta ) {
add_post_meta( $tender->ID, $meta, '', true );
}
return;
}
}, 10, 3);
Related Posts:
- How can I remove fields in the attachment editor?
- Add WYSIWYG to Image Description field
- Custom wysiwyg editor doesn’t execute shortcodes?
- Setting user permissions per post
- How to add content with a filter when there’s no content in the editor
- Importing data for advanced custom fields plugin?
- Gutenberg add a custom metabox to default blocks
- How to rename a custom field?
- Filter post listing by meta value which is a date
- Extra profile field as select box?
- Matching Serialized Arrays with meta_query
- Pre-filling custom fields on New Post
- Make Custom Field Into A Link On The Front End?
- How to activate “custom fields” section in WP3
- Why isn’t my code to save custom fields in quick edit working?
- Add meta data to the menu
- How to oEmbed from custom field, responsive to container size and responsive
- Custom Meta Boxes: Store two values in one repeatable field
- Copy SEO Meta Desc “Custom Field” to Excerpt field?
- Custom fields won’t display on my blog page
- How to customize default wordpress editor?
- Up/Down voting system for WordPress
- Problem in custom meta boxes
- Add an advert every nth Paragraph
- How to edit multiple post with Custom fields
- Undefined index error when saving content on metabox
- Metabox with multiple fields added by user and upload box
- How to update custom user meta field in wp?
- Get all meta keys assigned to a post type
- sort search results by custom fields using dropdown
- WP Custom Fields Metabox Disappears – ACF plugin issue [closed]
- Add conditional custom option to ‘Display name publicly as’ dropdown
- Custom fields not getting saved in the databse when added to the add new user profile page
- I want to send an email when each post is published
- Creating a widget with a number of custom fields
- How to loop through certain custom field values
- Show 1 post and after a specific date show the next one
- How to Create Dynamic Fields in a Meta Box?
- Set front page option using custom fields?
- Add post meta fields, when creating a post using WordPress’ REST API
- Custom Field Values not updating unless I click “Update” twice
- Can I create a template or doctype for my blog site?
- Custom field, add class to anchor tag
- Custom Metabox additional item
- How to combine custom fields to make one order-able value
- Updating Other User’s Metadata
- get_posts in meta box dropdown not showing latest posts
- Trying to reorder posts by custom field
- Delete custom fields when deleting posts
- Split the_title
- How to Wrote Simple Calculations by Using Custom Fields in Loop?
- Custom Query based on custom field of a single post
- comment meta_query for keys that aren’t yet set
- Link the retrieved custom field values to its respective posts
- Sortable custom field values from all posts on a page template
- How can I use custom properties to set different background on different pages?
- Values entered in a meta box aren’t saved
- change order of images attached to post
- Display meta box dropdown (from custom post type) in the page post type
- How to Make Post Custom Column Editable
- how can I show name and value of Custom Fields together?
- Adding simple (one button) Audio player using Custom Fields?
- Loop through incrementing custom fields
- tax query between operator like
- Single page WordPress website – custom fields or meta boxes or something else?
- Collect Data from NEXT item while in loop
- Order custom fields alphabetically
- How to query for posts with either one or another custom field
- How show post only from after custom date
- Is it possible to compare the current time with a custom “start” and “end date
- Display metabox title for custom fields with values
- Filter or order based on custom field
- Gutenberg add a custom metabox to default blocks
- How to use ACF with javascript to update custom field values?
- Custom Fields Not Showing (ACF not installed)
- Show Custom field value instead of title in WP Menu
- How to add code to custom field to every blog post via php?
- use mysql to replace one custom field value with another custom field value
- want to add video upload option for front end user
- Adding fields to attachment – only shows when inserting new attachments
- Saving and using Custom Field in user settings/profile “Checkbox list”
- How do I use foreach to get content from a custom-field in multiple posts?
- Is it possible in WordPress
- Related post thumbnail not showing up
- Edit different parts of a page seperately
- Copy url from post_content to custom field
- I want my post to republish again after adding a custom field
- Custom fields: dropdown values depending on other custom field value
- How do i get a specific user metadata using custom metavalue outside of wordpress?
- Creating an If/Else statement using WPAlchemy MetaBox radio boxs
- How to retrive Custom Fields as Values for a Form field
- Use custom field value as href
- Custom fields doesnt work well with any postTAB plugin
- Colecting values from custom field checkboxes and displaying them in the post
- Build Array from Input Fields question
- jaredatch metaboxes on video post formats
- Grouped Custom Meta Fields without plugin
- Google not index my Custom 404 page ?why?
- Dynamically update Custom Fields to display new dates
- save all acf options in one meta_value [closed]