You can use save_post
action which gets triggered when a post is created or updated.
https://developer.wordpress.org/reference/hooks/save_post/
In your function, you will have to check for your custom post type, set the value you would like to have to a variable, and pass it to the update_post_meta
function with giving the name of your custom field.
function my_update_on_save( $post_id ) {
if ( get_post_type($post_id) == 'your_custom_post_type' ) {
// Do nothing if this is a post revision
if ( wp_is_post_revision( $post_id ) )
return;
$value="your value";
update_post_meta($post_id, 'your_custom_field_name', $value);
}
}
add_action( 'save_post', 'my_update_on_save', 10, 2 );
Related Posts:
- Change the footer text on the login page
- How can I hook into and edit the text of a wp_nav_menu tag?
- Check if page parent has certain template
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Find variables available at a given hook
- Getting my head round WordPress filter
- How To Change The Html of Products filtration sidebar in Woocommerce?
- How to set a custom path, for ajax image upload folder in admin?
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- When using the_author hook, how can I determine the PHP file that generates each call to `the_author()`?
- How to call function at the bottom of post using plugin?
- Handling Body class based on Template
- Edit incorrect password message WordPress
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Remove a div from RSS feed
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- How to have different site identity logos on each page on Astra Theme [closed]
- Must filter functions receive all arguments passed to them?
- How to sort WooCommerce products page by latest in-stock items first?
- Filter wordpress posts without searching the keywords in the post content
- Variation prices breakdown only for single product page
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- using filter and hook inside class
- add_filter() inside another add_filter()
- Add class to all meta boxes for a custom post type
- How to add custom checkout field in user details mail template
- For each loop will not append to the_content hook
- Assign new post author IF another user in custom field on post transition
- Is there a hook that I can use when a fatal error occurs?
- Using register_activation_hook in classes
- Remove “Insert from URL” link in Media upload – WP 3.5
- Hide custom image sizes from media library
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to Remove a Filter from the Admin List Table?
- Woocommerce, recognize the loop of related products
- Insert all post IDs in new database table
- Filter get_the_title to remove certain characters?
- Reposition Woocommerce Message
- Get posts with at least one category in common with current post?
- How to add a second ‘place order’ button in WooCommerce [closed]
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- WooCommerce Related Products by Attribute
- Custom filter in admin edit custom post type responding with invalid post type?
- add_action shortcut?
- hook that when page is starting to load
- How to change home or site url using action hooks or filter?
- Ajax category filtering products default show all
- Add a specific part of current category page url to shortcode
- Add a product to checkout via form
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Remove the first 5 characters of the_title and orderby that
- Print last modified date only on posts
- Return a numerical function value in Customizer controls
- edit_comment_link is not showing for comment author
- Adding function to Genesis genesis_header [closed]
- Change tinyMCE editor to allow marked content when pasting from Word
- How to debug this search & replace strings snippet?
- Hide Featured Image Meta Box on Editor Screen
- Add item to top of menu using a filter in functions.php
- How to make modifications only to certain elements of an HTML string on the server-side?
- Password minimum length in personal subscription [closed]
- Theme activation hook in php class
- How can I hook into the wp_mail function used by BackWPup?
- Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?
- Filter by field with array value in ACF on WP REST API
- wrap a span tag around author’s post count
- Display custom field value in woocommerce variable product via jQurey
- Remove Author Links
- Apply function.php filter only if url not has /amp/
- Preserving backslashes in post_content
- Add a top bar to a wordpress theme without editing the header.php file?
- Get original value in save_post action hooka
- get Woocommerce product format json for WP_Query
- Is there an option to execute javascript file only on plugin activation
- How to change href of a Widget menu item link?
- How do I remove an action hook inside a class that is called by another class?
- Reload page with a different shortcode when a user selects from a dropdown
- Help hooking into user_register
- WordPress Ajax filter: Create two loops for different output styles?
- How to display custom seo title before the loop?
- Hook into all password resets in WordPress and get password before hashing?
- How to remove title tag with this filter
- Why transition_post_type hook is called twice for the same post?
- str_replace not preserving whitespace
- Add custom filter to register data in array
- Get terms of the posts with one query
- Woocommerce Price Text
- Limit Taxonomy Parents
- WordPress HTML Helper
- Display a post based on its metabox selection
- dynamically filter by category via sub-menu
- Change Checkout “Place Order” text if cart has a specific product
- How to add different menu items on different menus?
- transition_post_status hook, works – but not if the post is new
- php was updated – critical error [closed]
- Woocommerce – add tracking code to another email template
- Custom Filtering date with newsletter