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
- Firing schema via code in functions.php doesn’t work
- Adding number to date not working [closed]
- How can I add extra word in permalink when someone click download button?
- Saving and Restoring a Canvas on A Individual User Basis
- Seach custom post type posts only by meta fields?
- How to use thumbnail size of image if I’m only using src to get image
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- how to retrieve a value if a checkbox is checked
- 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
- Archive post by meta value + 24hours
- auto-populating custom nav with all items from custom post type
- Add / Update Custom Fields After Select Pictures in Media Window
- WordPress update_post_meta updating with empty meta_value field [closed]
- conditional logic for front-end custom field edits
- Trying to retrieve post meta
- Automatic Shortcode Creation with Custom Fields [closed]
- Custom field values to taxonomy terms
- How would an if statement surrounding a custom field with two variables (holding values) look like?
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- Custom Field IF/ELSE PHP
- Which PHP page is the Default Posts Page
- How to combine 2 php functions into one function with a custom field
- Remove the last X characters of a custom field value
- Advanced Custom Fields – display label and value only if value entered
- Get post id within comments loop
- Saving zero in meta box
- Find a way to retrive data updated through metabox plugin to web page
- Why are the details of my todo not saving?
- How to check if a PHP string is different than meta field?
- Can’t save php string to a custom field
- Display custom field on 404 page outside loop
- Why does this update_post_meta function not delete the custom field itself?
- How to show/hide php table rows based on the content of custom fields
- Run str_replace on title and save the output to a custom field
- Querying Database with wpdb
- update_post_meta only updating on last loop of foreach
- Only show image from custom field when present
- Hide Heading if ACF Field is empty
- Custom meta box values are not getting saved for my custom post type
- 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)
- WP_Query: getting posts where custom field exists
- How to show meta value code HTML after x paragraph
- Creating an image from a custom field
- User Meta Value not echoing despite Var_Dump Showing correct string
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress yoast seo plugin – parse snippet var in meta description
- if custom field doesn’t exist, use post thumbnail instead, as image background
- WP All Import / Update stock quantity from multiple XML files
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- How to add post meta in while loop?
- Add category to post meta
- Handling repeater data
- How to add data to a custom field at the wp_users table?
- Using rules in Posts
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Concatenate Custom Field Value & HTML Value
- Update post meta – Custom field does not match meta-key
- Output custom text field as unordered list
- Conditional featured image with youtube thumbnail
- `update_post_meta` not working anymore
- Save the value of a wp_dropdown_pages
- Unable to render custom field after attempt to generate a list of recent post in page template
- Add a counter for mouseovers (custom field)
- Unable to Call More than One Meta Box Output
- Including Custom fields within the_content
- How can i make a search box to search by custom field
- Update value of a associative array with update_post_meta
- Front end file upload returning wrong attachment url
- Comparing Dates from custom field
- Conditional On custom field plugin metabox
- Show field if it has contents on Advanced Custom Fields
- Adding custom url to readmore link using get_permalink()