A very easy way to accomplish this would be to add something like this into your themes functions.php
file:
function update_post(int $id, \WP_Post $post, bool $update)
{
// Case the post object to an array
$data = (array) $post;
// Set the title to the ID of the post
$data['post_title'] = $id;
// We need to remove the action to prevent an infinite loop
remove_action('save_post', 'update_post');
wp_update_post($data);
// Finally re-add the action hook
add_action('save_post', 'update_post', 10, 3);
}
add_action('save_post', 'update_post', 10, 3);
Notice that you can narrow down which post types to handle by using add_action('save_post_{$post->post_type}', 'update_post', 10, 3);
.
So if you custom post type is called video
then you would add the hook like this:
add_action('save_post_video', 'update_post', 10, 3);
Read more in the documentation:
Related Posts:
- what is correct way to hook when update post
- Call to a member function add_rewrite_tag() on null
- Why is my custom meta box input not saving
- Action ‘save_post’ not working for quick edit
- Save selected item from dropdown menu in a meta box as a metadata value for a custom post type
- How can i create a function to get youtube video time
- Second select list values are not saved after clicking update
- Update Custom Field on Imported Post Creation
- Set Primary category using the Yoast SEO plugin
- Executing `createimagefrompng()` from save_post hook (or equivalent hook)
- How to add custom taxonomy slug in CPT permalink?
- save imported posts as drafts
- Auto-Select Parent Category as Primary
- Can’t find infinite loop cause
- Custom meta box values are not getting saved for my custom post type
- update_post_meta() not saving data inside of save-post filter
- Class property seems to lose scope, attached to save_post action?
- save_post action inside a custom metabox class not working
- WordPress: Displaying all the post tags from within a specific taxonomy’s term
- How to check post meta isset or not empty during publish/save post?
- save_post trigerred twice
- Relationship between custom post type and page/single templates
- Save data of select list after clicking save
- Display a query with multiple post types and same relationship on a single page
- How to extend the page editor?
- Display all categories (with link) of custom post type – WordPress
- How can I get values from a custom post type depending on where I click on my SVG map?
- Displaying custom meta box value in a custom post page
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- WordPress different custom tag being displayed in on tag list
- How to enable REST API on custom post type without Gutenberg?
- Can I associate a custom post type with another custom post type?
- Get category name of current post (CPT UI)
- How to sort custom sortable column by custom table value
- I want to show image from custom field image on my custom page template
- How to disable page create for custom post type, but allow a page with the post types slug to be created?
- How to use multiple custom post types to archive as front page?
- How to make multiple custom taxonomies sit under custom post type slug?
- Limit a search box by CPT + taxonomies, in only one page
- WordPress taxonomy and terms question
- Load style and script for custom post type metabox
- Custom CPT – Programmatically create categories to assign CPT when a new one is created
- Why do I get a 404 error on my custom post type archive pagination?
- How do I exclude the current post from the upcoming post query
- Custom Filtering date with newsletter
- Ajax infinite scroll random order shows duplicate posts on custom post type
- How does printf( __( ) ); work?
- Displaying Logged-In User Name in WordPress Menu
- How do I add a php statement to a jQuery string
- Upload images and attachments from frontend form
- Config apple-app-site-association file with wordpress
- Should I use wp_mail or PHP’s mail? [duplicate]
- Successful or Error Message after running mysql code in functions.php
- Link to file in plugin directory from wordpress template?
- Trying to make php run in a post
- WordPress Site Running Extremely Slow on Dedicated Server
- Redirect undesirable domain
- WordPress Gravatar filter is removing my custom attributes
- Trying to install wordpress locally with mamp, but have unsupported php version
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- How to optimize the IF condition with many conditions and same output [closed]
- Show latest posts in a plain HTML website custom widget [closed]
- How to list posts from a plugin taxonomy?
- How to remove coupon dropdown feature
- How to put a form with php code into a variable or shortcode?
- WordPress redirect redirecting too many times or not at all
- Is there a way to create two template for single custom post type page?
- how to prevent wordpress admin from logging in via woocommerce my-account page
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- Problem with custom loop and wp_list_pluck [closed]
- Plugin: Front-end Editor – User role specific editable content?
- How to get post count of specific taxonomy that have store name & category
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- WordPress Custom Add To Cart Button with AJAX
- Custom reduce stock code affecting date_modified – How to bypass?
- Publish button now showing content after saving
- User filter posts by year
- Trying to call dynamic content into a 3rd party shortcode
- How to Create Carousel Indicators in PHP Loop using wp_get_attachment_url function?
- Limit Search to Product Pages only unless I’m on Blogpage or Blogposts
- WordPress wrong dates bug
- I have a background-image in css file but don’t show in site.how to fix this prblm. i sent screenshot. thx
- “Class Not Found” in HTML Form Target PHP File that contains the class
- shortcodes, custom php and their errors
- Should I use wp_cache in my plugin to make it faster?
- clicking on the_tags() generated tags to show all tagged posts page
- 403 Forbidden WordPress Database Results
- How to add custom text near category/tag title in WordPress Twenty Fifteen Theme?
- Woocommerce variable products are being added to the card on the homepage (ajax)
- migrating wordpress, but getting some php parsing errors
- Reformat data within a nested array
- How to resize an image server-side before upload?
- Show contact 7 form in popup
- Outputting a custom field in PHP
- Issues separating my Plugin pages into different files
- An automatic way to crop images of different sizes
- Blog listing not showing dates for every post and arrow missing off image
- Custom form that stores data in mysql database
- How to get data (not value or name) from radio options to POST to database
- Why is my custom email notification after purchase not sending?