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
- WooCommerce: change display order of product short description and price [closed]
- Use wp init hook to call other hooks?
- Hook that fires when admin setting is saved
- What is the difference between update_post_meta and update_postmeta hooks?
- Is there a WordPress core & plugins update action hook?
- is it possible to get the hook name in add_action?
- What hook is executed just after wp_query has been executed?
- Use $query->set multiple times with pre_get_posts?
- How to properly test a method that is called by an action hook
- How can I do customizations on login, registration and password recovery forms?
- Custom form action hook
- Hook before inserting user into database [duplicate]
- How to send an automated user ‘inactivity’ email?
- How do I successfully create a hook for an email override?
- Placement of Code in Plugin for hooking `save_post`
- Which Hook? Hide attachments from specific post types in media library
- Cast string to number
- How to debug user_register hook
- Storing state between hook functions
- How to hook into Add New Member in BuddyPress
- What’s the difference between “wp” and “wp_loaded”?
- Hook when new CPT published AND postmeta inserted
- Need to check is_archive during init
- When WP_CLI runs WordPress from the command line, are hooks called?
- Query categories that have a description
- Update a costume wp_usermeta key back to 0 every 24hours (time can be specified as needed)
- How to change image atributes right before an image to be saved?
- Trying to run a compile command while saving post
- When are wp redirect methods safe to hook?
- WooCommerce single product page quantity description [closed]
- Execute JavaScript in WordPress Hook
- Action hook for custom tax edit
- wp cron job fires at every second or so, if callback is wrapped with DOING_CRON check it never fires at all
- wp_enqueue_script before wp_head
- Is it possible to add the_content filter upon login?
- I don’t understand how add_action and do_action work in tandem. The former executes the code already…what is do_action for?
- Insert HTML in post, below nav bar but above content?
- Convert Gravity Form Entry Date on Export
- Hook Adding content after title
- Fatal error: Call to a member function get_queried_object_id()
- “admin_enqueue_scripts” hook or $_GET[‘page’]?
- wp_logout hook never triggered
- add short description under price
- How do I use pre_option_{option_name} correctly?
- How to add content to suscriptor dashboard frontend?
- Custom Meta Box (SELECT2) Not Saving Taxonomy Terms
- Add PHP code to header section from plugin
- How to change a WordPress term’s slug before saving
- dynamic add_action according to child pages (for homepage control)
- Remove action in a parent theme from the child theme
- Remove action within a class in a parent theme’s includes folder from the child theme
- WordPress media library allow uploading fake file
- Action hook save_post for newly created posts – $post object data is all empty
- add_filter to the_content from plugin function
- What hook should I use that will fire whenever I open a post for editing in the WP back-end?
- Hooking dynamic/variable named hook in all cases
- Can not using get_header() cause trouble (later on)?
- Is there a author_update action?
- Catch and display error on save_post action
- How to set Media Box form elements default value?
- How to get product information using hooks?
- Print additional fields in wp_new_user_notification_email_admin
- Can we change the hook firing sequence?
- Intercept loading of a certain page
- remove_action not working for a function
- Is there no concise way, a library maybe, to help with unhooking class functions and so on?
- Output Redirect Headers on Admin Dashboard Page
- Debug a WP install: how to find which functions write post updates during a process (a woocommerce checkout in my case)
- What hook should I use to add post meta data with on update?
- Problem with call_user_func_array front end
- How to I prevent WordPress from switching external HTTP links to HTTPS?
- Stylesheet is getting removed/deregistered automatically
- How to override get_avatar() function?
- Change user role if it’s orders count more than
- Hook triggered twice in a Woocommerce single product page
- Using actions, hooks and filters in a non-WordPress page
- Hook into create_category
- Trouble adding data to options table
- Getting all post/page IDs related to a soon-to-be-deleted tag/cat
- Hooking get_pages()
- How to hook into publish_posttype?
- Transform .wp-video to the native video player of the browser
- $GLOBALS & global doesn’t work [closed]
- Hooks not working on live server
- Callback API for getting response from fygaro payment gateway
- Changing login url