This simplest method would be to edit the data at the point it’s inserted, rather than updating it afterwards, using wp_insert_post_data
instead of save_post
. This works on creating a new post or updating an existing post without change. It also avoids the danger of creating an infinite loop by triggering update_post
within save_post
.
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 1 ); // Grabs the inserted post data so you can modify it.
function modify_post_title( $data )
{
if($data['post_type'] == 'rating' && isset($_POST['rating_date'])) { // If the actual field name of the rating date is different, you'll have to update this.
$date = date('l, d.m.Y', strtotime($_POST['rating_date']));
$title="TV ratings for " . $date;
$data['post_title'] = $title ; //Updates the post title to your new title.
}
return $data; // Returns the modified data.
}
Related Posts:
- Prevent post from being published if custom fields not filled
- Why won’t my metabox data save?
- Custom post type save_post action not firing
- Submitting posts from the front end – sanitizing data
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- Is there an easy way to AJAX-ify saving of post?
- Custom field values get deleted
- Change 2 fields in the post depending on the 3rd field before save
- Unable to save or update postmeta for custom post type via action using save_post hook
- update_post_meta() whenever custom post type is updated
- Trigger “unsaved changes” dialog for custom post meta changes
- Frontend posting – everything saves other than checkboxes?
- Custom Post Custom Taxonomy Data Not Saving in Edit Screen
- Is it possible to create a post using a metabox?
- Confusion regarding Nonce & using it in Custom Columns for Saving Checkbox Value to Post Meta
- How to get updated data when save_post triggers?
- How can I set taxonomy programmatically
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- Troubles with acf/save_post and WP_Query
- CPT Validation to not show “Post updated.”
- save_post custom post type ? $_POST not working?
- Custom Post Meta from custom metaboxes is randomly being deleted
- Mutiple Select only POSTing 1 value
- Custom Post Type Metadata Not Saving
- detect when a custom post is cretaed for the first time
- What do the numbers mean at the end of add_action(‘save_post’)…?
- How check if a post is saved from backend or frontend?
- How to detect that the save_post hook is calling the callback associated to the current edit post page only
- How to prevent meta data from being edited in a post?
- Catch and display error on save_post action
- Custom Post Type Meta Box Text Input Field Won’t Save When Blank
- Save post action is called twice
- Urgent – WordPress keeps creating posts
- How to check for duplicate record before saving a Custom Post Type
- Custom post types saved as basic post
- Save_post acf data not updating category of post type
- Post meta is not accessible within save_post hook
- Custom post type meta fields missing on save_post_type
- How to save post_status using action save_post?
- How to stop post status from reverting to Published?
- save_post affect creation and deletion
- Link two different post using there post_id in post meta
- Custom meta box data not saving
- How to implement custom post type’s users
- How to hook save-post function to use taxonomy term in post-slug?
- Metabox is not saving
- Generate slug and meta data if meta field is empty
- Problem with ‘save_post’ hook not running
- Not Able to Display Metabox Saved Checkbox and Selected option After Save/ Update
- Function that get ACF fields value before saving
- How to use wp_set_object_terms depending on page ID?
- Advanced search form with filters for custom taxonomies and custom fields
- Use a separate upload folder for custom post attachment upload
- Assign posts to taxonomy terms instead of the taxonomy terms to posts?
- Custom Post Formats for Custom Post Types
- Get all posts from custom post type and insert in select input as metabox
- How do I get a meta value from WP_Query?
- Custom Post Type or Custom Tables
- Group search results by post type, but hide post types with no results
- same archive template for different custom post
- how to set default value for checkbox in wordpress
- wp_update_post based function works on existing posts, but not new posts
- Impossible to get Attachments Outside WordPress?
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- Taxonomy Templates
- Custom post type code hides navigation
- Is it possible to create a shortcode that will query a post based on taxonomies?
- How can I show/add/save custom metaboxes as an Array of values?
- Query Multiple Meta Values and display only when it has both meta values
- Custom Post Types – Change order of menu items
- What template files do I need to customise custom-category-term-links rather than fall back on archive.php?
- wp_update_term_count_now doesn’t work with a custom post type?
- Custom post types as sub menu pages and role capabilities issue
- Add custom field in comments form
- WordPress request fiter order by related post’s post_title
- Best method to make posts searchable, sortable and filterable – custom field, tag or category?
- How to use manage_$post_type_posts_columns with underscore in post type?
- How to specify a template for a path like http://example.com/something?
- Categories and tags for custom post types
- WordPress 3.9 not using custom template
- uploading problem of wordpress theme
- Pagination doesn’t function properly for archive of a custom post type set as the front page
- How do you make a list and list item relation if custom post types?
- Two custom post types divided in two columns inside a bootstrap carousel
- Getting array_merge(): Argument #2 is not an array on register_post_type
- How can I relate custom post types?
- Display author box on just certain category posts?
- “Order” doesn’t work in custom loop?
- How to divide Subcategories into pages of parent category wordpress
- Is there any filter to add a custom attribute to the tag in admin panel?
- Tell wordpress to show a single page instead of an archive page
- Post display in separate page [duplicate]
- Create dynamic logo carousel without using any plugin
- Delete Post by User
- Test for post type in request filter?
- Have two (permalinks) urls for a same custom post type
- If taxonomy show class of active
- How to loop through custom posts in admin edit screen
- querying to custom field over ACF REST API
- Fatal Error WordPress Custom Post Type UI + WPML