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?
- how to append ACF field data using one of the following filter/ hooks
- Reload part of checkout on changed shipping method
- Trying to build simple deposit code that hooks into woocommerce
- Removing “wpautop” (auto tags) only on certain pages?
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Remove metabox from WordPress menu editor page?
- Add a product to checkout via form
- Add filter when image is uploaded?
- 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
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Print last modified date only on posts
- user_profile_update_errors hook not executing
- Set meta field to publish date + 2 weeks
- Error in custom php function doesn’t exist
- Don’t insert if permalink is the same?
- Return a numerical function value in Customizer controls
- Adding widgets to my plugin page instead of WordPress dashboard
- Unique icons next to each WordPress menu item
- edit_comment_link is not showing for comment author
- Adding function to Genesis genesis_header [closed]
- Modify custom field input data before creating a new post
- how to make custom ajax handler?
- Are all hooks/functions tied to Kses meant for sanitization?
- Change tinyMCE editor to allow marked content when pasting from Word
- Problem with login form
- Alter required message using comment form api
- How to debug this search & replace strings snippet?
- Why does wp_head hook my functions to the beginning of my source code?
- Pass argument to event hook
- Hide Featured Image Meta Box on Editor Screen
- Add item to top of menu using a filter in functions.php
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Should `wp_login` be used since it’s deprecated?
- Add filter multiple times using only one master function
- How to edit php code in WordPress Post file?
- Change page title from page using php via php executed from page/post itself
- How to make modifications only to certain elements of an HTML string on the server-side?
- Override a function defined in wp-includes/comment-template.php
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- Password minimum length in personal subscription [closed]
- How to use a custom hook
- Run a code only on theme activation only during first activation
- Theme activation hook in php class
- Filtering a function’ output for a new continued function
- Deleting Certain terms from appearing on the front end as links
- Theme not calling Jquery properly
- Content filter won’t work
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Get access to variable from previous pageview, excluding ajax-calls
- How to catch wordpress post ID when it’s published
- WordPress redirect redirecting too many times or not at all
- Why does the post_type_link hook everything twice?
- Warning: in_array() null given in PHP function
- Upload multiple files in randomly generated folder using wp_upload_bits
- Create page template via functions.php?
- Add meta tags to a custom header
- Ajax filter button display all posts
- How to append to an array and return the results in a filter?
- 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)?
- WordPress: Add custom add_filter for custom functions
- Get user custom field value on function.php
- How do I create a secondary version of the_content
- Get the_content surrounded by instead of
- Custom query vars filters problem with pagination
- Filter by field with array value in ACF on WP REST API
- Send notification email to admin for every new post published