Use the hook ‘save_post’ that pass 1 arguments: $post_id. Update_post_meta won’t trigger save_post.
add_action('save_post', 'custom_add_meta', 10, 1);
function custom_add_meta($post_id){
update_post_meta($post_id, 'meta_key', $value);
}
Related Posts:
- How to hook update_post_meta and delete_post_meta?
- Are there any hooks that alter the 404 logic?
- WooCommerce: change display order of product short description and price [closed]
- Use wp init hook to call other hooks?
- What is the difference between update_post_meta and update_postmeta hooks?
- How to remove action hook done in a plugin from functions.php in my theme?
- Hooks for trashing, deleting, saving, restoring custom post type
- Is there a WordPress core & plugins update action hook?
- trigger save_post event programmatically
- Implementing advanced add_* function wrappers
- Hook into wp_head(); in a plugin
- 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 can I hook into the post editor title field in order to change the HTML?
- 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?
- WordPress v5.0.3 Gutenberg & JS error “Uncaught SyntaxError: missing ) after argument list”
- Searching hook to set cookies before and avoid “headers already sent”
- Custom form action hook
- Hook before inserting user into database [duplicate]
- How to send an automated user ‘inactivity’ email?
- wp_redirect() not working on form submission with init hook
- How do I successfully create a hook for an email override?
- Cast string to number
- How to debug user_register hook
- Storing state between hook functions
- Using wp_editor tinyMCE in metabox cause form alert on leaving page
- What’s the difference between “wp” and “wp_loaded”?
- WordPress capabilities and restricted categories access
- Need to check is_archive during init
- When WP_CLI runs WordPress from the command line, are hooks called?
- How to use custom form on add_meta_boxes callback
- Is it possible to switch Gutenberg’s editor styles when document settings change?
- schedule event in class oriented plugin
- How can I find the hook I need to rewrite a function?
- Show message in media-new.php
- Hooks are not being removed in child theme
- add_action second argument missing
- How to get user meta fields that have just been updated?
- admin_notices action doesn’t trigger within save_post action
- When a plugin gets updated from the repo, does the “activation” hook fire again?
- 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?
- Hook Adding content after title
- Fatal error: Call to a member function get_queried_object_id()
- “admin_enqueue_scripts” hook or $_GET[‘page’]?
- Defining hooks within (php)classes?
- Divi hook not working [closed]
- Add WordPress hook outside of Plugin or Theme
- How to add content to suscriptor dashboard frontend?
- How to perform action when plugin/theme editor is used?
- How to run hooks one by one manually?
- Action hook save_post for newly created posts – $post object data is all empty
- add_filter to the_content from plugin function
- What is the proper hook to use for recording a post view?
- How to load this code on function.php
- What hook should I use that will fire whenever I open a post for editing in the WP back-end?
- Woocommerce single_product_summary hook not working
- Where is publish_post hook fired?
- A good hook to check authorization and redirect?
- Is there a author_update action?
- Bloginfo hook – can it be more precise?
- Custom posts and get_post_meta in {$post_status}_{$post_type}
- Hooking custom PHP output into WP: how to do it, parse_request almost works but not quite
- How to set Media Box form elements default value?
- Print on screen during shutdown hook – error during saving in theme-editor.php
- How to stop execution of a function via add_action hook?
- changing genesis_before_while in new theme framework
- Moving Javascript from footer to header
- Adding a new hidden field based on a condition in Ninja Forms
- Forcing WooCommerce customers to create account before checking out
- Store user ID on wp_term_taxonomy when new term inserted
- ‘user_register’ hook – need to distinguish if created from wp admin panel
- Make multiple URLs behave as home page
- remove_action not working for a function
- Debug a WP install: how to find which functions write post updates during a process (a woocommerce checkout in my case)
- 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?
- add extra parameter in default hook in wordpress
- Change user role if it’s orders count more than
- Hook triggered twice in a Woocommerce single product page
- set_post_format called after wp_update_post when using bulk edit?
- Using actions, hooks and filters in a non-WordPress page
- Hook into create_category
- Trouble adding data to options table
- Hooking get_pages()
- How to hook into publish_posttype?
- Fire a hook programmatically
- How do I override the user’s input when updating a custom post type’s permalink?
- How to add a new link to the default register form’s footer links?
- $GLOBALS & global doesn’t work [closed]
- Hooks not working on live server
- Use wordpress search hooks to search a second database
- Why callback function is not working in wp_head hook?
- woocommerce_add_to_cart_validation max quantity depending on user geoip [closed]
- theme.json is altering Group block HTML
- Not able to set userId and email at wp_set_current_user in Worpdress