Seems like you need to change your action to publish_post
.
publish_post
only fires when a post is published.
The callback function will only receive only one argument, the post id, with it you can do all your needed checks and update the meta as needed.
By the way, update post meta doesn’t play well with ACF in the initial update. If meta field was empty it will sometimes not update it.
Acf has its own function to deal with meta updates update_field, better use it instead.
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- How to display multiple Post meta_key/meta_values by SQL query
- How to use multiple query with same meta key
- How can update custom meta for all posts
- Use ajax to update_post_meta
- how to increase custom post value by one most efficiently?
- How can I create a list of page titles from custom meta values?
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Is it possible to retrieve all posts with a certain value for metadata?
- Non-Closing PHP Query in WordPress Loop
- how to get serialized post meta
- WordPress loop by meta key that is an array? and how loop multiple arrays
- How to store multiple custom meta box
- Order a WP_Query by meta value where the value is an array
- Add a custom class to the body tag using custom fields
- Define category ID using get_post_meta
- Hide a div when a custom field is empty
- WordPress stripping out custom field tags
- Order category posts by last word of custom field
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- WP post meta – for loop inside for loop
- When working with a post, almost all wp_postmeta are deleted
- Updating Lat and Lng of posts automatically gives sporadic results
- If custom field doesn’t exist, or exists and it’s true show title?
- Metadata on the WP_Post object
- Get meta_id along with meta_key and meta_value
- How can merge two arrays values in one array and save in database
- How to handle a custom form in wordpress to submit to another page?
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- Getting movie and serial on actor page
- Match checkbox data with page title to show certain items
- Why is my get_post_meta always empty
- Geocoding an Exploded Custom Field Array
- Compare two meta key values against each other inside the get_posts array?
- Removing WordPress profile fields from non-admins
- WooCommerce: update custom fields after checkout validation failure
- If Meta Checkbox is checked, do something?
- Show custom field if it exists, and show different elements if it doesn’t
- Change description on specific WooCommerce product status change
- Custom field value not saving when it contains a URL?
- Use WP_Query in shortcode
- tracking number field in Woocommerce order [closed]
- Trying to remove post thumbnail with plugin
- Sort posts by custom fields value using dropdown menu
- Creating user status mode in WordPress
- Need Help Fixing My Iframes [closed]
- Trouble checking if custom woocommerce checkout field is empty or not
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Add / Update Custom Fields After Select Pictures in Media Window
- Remove the last X characters of a custom field value
- Get post id within comments loop
- Find a way to retrive data updated through metabox plugin to web page
- Why are the details of my todo not saving?
- Can’t save php string to a custom field
- How to use two meta_compare in an array?
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress yoast seo plugin – parse snippet var in meta description
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Handling repeater data
- How to add data to a custom field at the wp_users table?
- Using rules in Posts
- Save the value of a wp_dropdown_pages
- Add a counter for mouseovers (custom field)
- Including Custom fields within the_content
- How can i make a search box to search by custom field
- Show field if it has contents on Advanced Custom Fields
- the_meta – no get_the_meta query?
- Display Custom Field in Sidebar if Value is Present
- Using a string from a custom field within a link
- Make separate text boxes for separate WordPress Custom Fields
- Dynamically added custom fields not displayed on WooCommerce email notifications
- get value from get_post_meta then reuse it in another get_post_meta
- Display custom field value in woocommerce variable product via jQurey
- Include custom fields in search
- update_term_meta() only updating once on certain meta keys
- How to Call on WordPress Custom Fields without a Plugin
- Query on a repeater date (acf)
- Using zip code to display custom data in Admin Order Details
- Generating 3 random numbers and saving them in database
- ACF – Can’t get custom post type by taxonomy
- Save custom field on WP_List_Table
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- custom fields anchor points php
- What syntax is this? “{{post.price}}”
- How to get the first letter from custom field?
- Meta box not saving spaces
- custom field meta-box with dropdown/autocomplete
- If Elseif Query
- get_post_meta is always empty when I use wp_mail
- Display custom meta box in my template file
- How to display the date under the post title?
- Too many if’s and else if’s ?? – Must be better way [closed]
- Advanced Custom Fields Show PHP in Text Areas
- How do I get a function to work in single.php
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- I want to show image from custom field image on my custom page template
- Custom Admin Menu Report for Specific User ID
- How to modify default tags in wp_head()