It all depends on how your “custom fields” are saved. If you store the values as post meta then you would have to call the update_post_meta function to update them on wp_insert_post_data. In the example below Im setting the post meta “my_meta_key” with the string value “my_meta_value”.
function save_my_post( $content ) {
global $post;
if( isset($post) && get_post_type( $post->ID ) == 'post' ){
update_post_meta( $post->ID, 'my_meta_key', 'my_meta_value' );
}
return $content;
}
add_filter( 'wp_insert_post_data', 'save_my_post' );
Related Posts:
- Wp_update_post: Infinite loop even with remove_action solution, OOP
- remove_action(‘save_post’) in function that was triggered by save post not working
- set_post_format called after wp_update_post when using bulk edit?
- trigger save_post event programmatically
- Is it possible to save/modify a post without calling the “save_post” action hook?
- Returning ACF custom field from publish_post
- How to check what kind of saving it is?
- Conditional for autosave or auto draft?
- save_post hook to add terms getting deleted when using bulk edit
- ‘save_post’ hook not working in WP 3.5
- Is there a before_save_post hook or something similar
- Add action save post when create and publish
- WordPress save_post hook not firing when checking if _GET[‘post’] is set
- How do I set a custom post type Category after import using wp_set_post_terms
- Show admin notice if metabox field is empty during save post
- update ACF field when saving post on back office
- How many times can I hook into the same action?
- Is there a hook before the user is authenticated?
- switch_to_blog(): Load textdomain
- Can I hook inside another hook?
- Adding function directly vs using hook in function.php
- What is the action hook for save media-form on gallery tab?
- Check if action hook exists before adding actions to it
- Post-Registration, post-meta hook?
- Get updated meta data after save_post hook
- after login that will redirect user role into a page
- Access post meta just after publishing
- update post meta using user_register hook not working
- how to create endpoint for downloading pdf files?
- hook to get (and change) the search string before processing
- Is there a recover_post hook to go with trash_post hook?
- How to override languages files in wp-content/languages/themes with child theme
- hooks & filters and variables
- How to increase password requirements for registration [closed]
- Can user_register output the password?
- Run add_action hook if condition
- Gutenberg gallery hook errors
- How to change title attribute returned by comments_popup_link()?
- How to use do_action_ref_array?
- Problem using role_has_cap hook
- How to find hooks as per Just-In-Time approach?
- WordPress action and filter hooks runs asynchronously?
- Prevent attachment from being deleted
- Update post meta using pending_to_publish hook
- Hook for when a page template is changed
- Footer.php being inserted before article closing tag?
- Get all posts with a duplicate name
- Save acf field data via acf/save_post before post is saved
- Above-the-fold inline styles from SASS generated stylesheet
- Redirect in form handler causing form to be submitted twice
- Checking login status before wp_get_current_user is initialised
- Add media library tab
- Conditional hook [closed]
- Add_menu_page() error message -> “You do not have sufficient permissions to access this page”
- Send along login credentials with comment content
- How to replace a function using a child theme?
- How to pass argument to wp_footer hook with data from a template
- Redirecting from login
- How to use a 3rd party library to send emails?
- I would like to send a notification email (Asana) whenever something is published (posts, pages, custom post types) [duplicate]
- Woocommerce table is missing a heading–can I add it by use of a hook?
- register_deactivation_hook argument -> pass arguments in the selected function
- Alternative to new_to_publish Hook for Custom Statuses
- Force file download in WordPress
- How to use pre_get_posts
- hooks for automatic approve user registration according to data in custom fields
- How to render an element, that was saved as a template, using a hook?
- How to use embed_content hook?
- Notify admin when Custom post meta data gets updated or deletet
- Action hook with wrapper html
- How can I edit comment meta value before it is saved?
- call php file from form and use wp functions
- wp_insert_post hook for a wordpress plugin
- WordPress add_action the_post hook
- save_post trigerred twice
- Session management issues with WordPRess 404 Error page
- Template_redirect works, but headers aren’t sent when checking via cURL
- template_redirect hooks redirect wrong URL
- Add a Call to Action Button to WordPress Post Thumbnail
- Easy Digital Downloads – How to use hooks correctly?
- Updating a related post’s “post_modified” value
- Get Category in save_post Hook
- adding wordpress yoast SEO canonical url from “transition_post_status” hook
- Cookie cant be read even cookie is present
- How to create callback function which returns all posts with specific data?
- remove_action() hook not working
- Why the post ID is 0 in a hook within wp_insert_post_data?
- How to work with hooks and Posts to posts plugin?
- When is get_currentuserinfo() needed?
- disable publish button until condition is not met
- How do I remove an action hook by s2member
- How do I change TinyMCE button “i” to create a i tag rather than em? [duplicate]
- How can I modify the code generated for a PDF by the Add Media button in Classic Editor?
- Taxonomy Child Not Updating Unless I Click Update Twice
- Do New_to_publish hooks work for custom post types
- Creating my own “recent blog posts” static Gutenberg block, can’t use react hooks in the frontend
- Hooks to trigger a callback when adding, removing, rearranging or updating a widget in the widget area
- Replacing specific Gutenberg blocks
- dashboard_activity hook
- Hide Description field for custom taxonomy?