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
- Custom post type removing /page/2/ from URL when trying to access it
- Same Custom Post Type Slug and Custom Taxonomy Slug, with hierarchial unique permalink structure
- fetch from an external api call and display results in page
- WordPress CPT & Custom Taxonomy with the SAME Permalink Structure
- Remove slug and custom post type name from URL
- Hot to show custom post type taxonomies on archive page
- Integrate a Custom Post Type with Learndash Plugin
- child category under correct parent
- Remove slug of multiple custom post types with and without hierarchical
- Redirect WordPress page to the latest created post by the logged in author/user
- create custom post type and populate custom fields using php
- Want to add custom post type for facebook feed
- Custom Post Types in WordPress Dashboard List Rows But Data is Blank
- Options of select field in a custom divi module ignore sorting
- How to Customize the Admin Sidebar Menu in WordPress Multisite Network by changing the backend code of the wp-admin code files?
- Why does my custom slug only show in Gutenberg editor after page refresh?
- How to get the post title inside a custom block in a loop? block.js
- Set custom post type to load custom block pattern by default
- Post returns 404 after changing the permalink using post_type_link
- Combine CSS and JS files from plugins
- username_exists() function can’t be access without logging in
- error importing localhost export file to server
- Get value of contact form 7 radio button [closed]
- Return array of categories to php function for current post
- Create dynamic pages from external JSON data without storing in Database?
- database interactions using OOP
- How to send get request to file.php right and where to store that file.php?
- Pull Tags But Not as Links
- Define specific category name in PHP
- Can I get an email notification when media is uploaded to the media library?
- PHP Syntax Error on get_posts
- Add value to new attribute inside WordPress menu items
- Please show me how to use an if/else statement in combination with wp_enqueue
- Count foreach and display in menu php
- Function to erase every post from a taxonomy
- Group episodes by seasons
- Custom URL for multiple categories hierarchy
- if get_post_meta is empty echo a placeholder or shortcode
- Admin Panel 404 Error after login
- in_array not working on dev server but works on localhost
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- Unable to insert two value in two different columns (WordPress database)
- Import Instagram post as WordPress post
- How to put a before and after with tags in a wordpress entry?
- How to call a WP Class inside my theme
- HTML Formatting “single_term_title()”?
- Adding a widget under an ‘Add to Cart’ button through a PHP snippet
- Allow Submit Contact Form Default Text In Text Box
- Front end/Database connection in WP
- Div Missing In Custom Loop Query
- Global variables and re-use
- FATAL ERROR , Sommerce Theme [closed]
- How do you create a front end form that enables the editing of member-specific custom fields in WordPress?
- WordPress Customizer – How to save list of checkbox of pages?