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
- Quiz page template, checked attribute missing when option selected
- Redirect WordPress page to the latest created post by the logged in author/user
- Is it possible to go to the next post in the same category?
- Send summary email from a form with wp_mail
- 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
- How to Bulk Update CPT Taxonomy Values Using CSV Lookup Table
- Set custom post type to load custom block pattern by default
- Post returns 404 after changing the permalink using post_type_link
- Cannot access the other pages after successfully editing post type
- How to select WooCommerce products by post_meta and order them
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- If search results empty then execute certain code
- Create dynamic pages from external JSON data without storing in Database?
- Link for Most Recent Post
- wp-load Without Loading the plugins
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- Where would I place `wp_footer();`?
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- An unwanted inline style is added to my body tag
- How can I generate random numbers inside my shortcodes on each implementation?
- Shortcode return function with link href inside PHP
- Parsing php string in jquery [closed]
- Setting All Drafts to ‘exclude-from-catalog’ in WooCommerce
- custom widget on the footer
- How to properly insert a link to a template in WordPress?
- Can’t load WP function into external function
- Difference between ‘type’ => ‘text’ and WP_Customize_Control
- Woocommerce – Filter Variable Products by Variation Attributes and Variations Regular Price
- Loading header.php on specific page
- Locating Global Variables
- doing an ajax request always outputs 0
- Displaying a button on each post
- How can I add an alert (like the old javascript alerts) to my WP page?
- Admin notice not displaying
- Insert array data on plugin activation
- Auto crop images in WordPress
- PHP in post content [closed]
- Trying to make php run in a post
- Hide post if matches current month and year