It duplicate because when you run the wp_update_post()
, it will use the wp_insert_post()
function and the action save_post
will run again.
please use the filter wp_insert_post_data
to filter the value before save. https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data
Example:
function wpse309780_filter_post_data($data , $postarr) {
$data['post_name'] = wp_count_posts( 'post' )->publish;
return $data;
}
add_filter( 'wp_insert_post_data', 'wpse309780_filter_post_data' );
Related Posts:
- Perform function on publish AND save (not just save)
- How to display custom field in woocommerce orders in admin panel?
- Programatically add options to “add new” custom field dropdown
- Get a list of all available fields in the User Profile
- Enabling shortcodes for custom fields
- Add options to featured image
- Authors details such as social media links, emails etc → Is this Meta or something else?
- Remove image from post_content on save_post
- How to auto-update child posts whenever the parent post is updated?
- Assign category using custom field?
- Function to Download External Images to My Site
- How to run a function once on every post in database?
- Checked() showing up twice in custom fields
- How to use max and min values of custom fields
- Woocommerce Storefront WordPress Ignore Media Gallery Images and use External 3rd Party Host
- Customizer field value into functions.php variable
- Auto delete post if certain custom field data is empty
- Execute function after a post has been published
- Publish/Update post is changing image links from file url to post url
- How to display custom option field in woocommerce orders in admin panel?
- How to add a slide toggle to the Woocommerce-Layout__Activity-Panel area in the orders admin page
- What WordPress function to use to get meta value by using meta keys?
- Removing custom meta data
- Change label for registration Fields
- Custom Attachment Caption Fields
- Default Custom Field Value Automatically Update
- Events: Check for other event with same start date and category [closed]
- ACF not showing
- Remove a category from a post when saving a new post
- How to retrieve the values of a sub-field in the first and last row of an (ACF) repeater inside function?
- How to get correct value from checked()?
- Prevent custom field from being updated after first publish
- Custom Behavior when Adding New Custom Post Type in Dashboard
- Custom meta box values are not getting saved for my custom post type
- Programmatically add Yoast meta description after post save
- Can’t add_action to ‘save_post’ and get it to fire
- Insert Address fields into function
- How to make custom comment fields required
- How add body_class from wp_termmeta
- How do I display a date correctly that is stored in the database as a backwards 8 digit number from Advanced Custom Fields? [closed]
- Sort and display pages with specific custom field (not tag)
- shorthand syntax for custom fields
- Fill empty custom field with other custom field
- How to Display WooCommerce Product Price in WooCommerce Archive
- How to change text color depending on the number value (Using javascript)
- wp_set_object_term via js btn frontend
- Populate Product Regular Price with a calculated ACF Field Value
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Create New User Custom Field not Saving
- Creating a “Related Meta” type field?
- How would I correctly implement a new if statement in a child functions file?
- Hide empty custom field
- save_post function keeps triggering: Warning: array_map(): Argument #2 should be an array… when restoring from trash
- save_post doesn’t correctly process function call with php class
- How To Show Shortcodes In WordPress Custom Fields?
- How to echo the translated custom field?
- How to add function to custom fields when page/post has a password?
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- Post date on Custom field
- Dynamically generated Navigation Diagram using Custom Fields
- Define an extra field for all pages (with no plugin?)
- update_post_meta not working in function
- Adding custom field in menu options [duplicate]
- How to display data from custom fields in my custom shortcode?
- Syling Custom Fields echo’s from from functions.php
- does acf_save_post cause endless loop?
- Add custom fields after post/page title
- Adding and updating repeating custom field meta data
- Change Post status based on custom field date +1 day
- Get category of post inside save_post hook
- Increment price for Woocommerce Minicart [closed]
- Change woocommerce products weight varation based its product category or tags? [closed]
- Completely disable RSS feeds on WP 5.5.2 and show a 404 page instead of die();
- Check if row exists before inserting
- Removing the main link to Jetpack from the menu
- Defining a global array in functions.php?
- Set quantity of woocommerce product on page visit [closed]
- get_post_type() in in_array doesn’t work for some reason
- How to remove set_post_thumbnail_size() in child themes?
- How to load jQuery in the footer – nothing works for me
- how to en-queue jQuery to load before the tag
- Can’t filter wp_get_attachment_link
- Impossible to call wordpress function inside an include?
- How to stop wordpress from injecting hard-coded style into image attachments with captions
- Two functions with different arguments and add_actions, but identical code
- How to fix get_the_category function returning incorrect slug?
- Disabling visual editor on a specific post
- Testing for a shortcode using a function. 404 page throwing PHP Notice
- Function to check if custom page is used by page?
- Bizarre Child Menu Issue on WP Site
- get variables data from functions.php to template wordpress (without global variables)
- how to increase connection time
- Shortcode to insert default text and change one word throughout it?
- Hide disclaimer from summary excerpts
- Open image size links in a page instead of direct image link
- Function to get thumbnail img source
- WP Custom Comment Callback Not Responding
- Do something when user creates post (that’s pending)
- How I can show short content with short tag