I think a good way to do what you want is hook the wp_insert_post_data
filter. Here you can change the title and slug of the post before it is saved to database:
add_filter( 'wp_insert_post_data', 'wpse_update_post_title_and_slug' );
function wpse_update_post_title_and_slug( $data ) {
//You can make some checks here before modify the post data.
//For example, limit the changes to standard post type
if( 'post' == $data['post_type'] ) {
//Add post meta to post title
$data['post_title'] = $_POST['the-name-field'] . ' ' . $_POST['the-surname-field'];
//Update the slug of the post for the URL
$data['post_name'] = sanitize_title( $data['post_title'] );
}
return $data;
}
Related Posts:
- How to add a theme custom variable to a post title?
- Create additional short URL with custom field and 301 redirect
- How do I get the url slug inside the dashboard for a custom post type?
- Split the_title
- How can I modify RSS item titles to be either the title or a custom meta field?
- Shortcode To Display Post Custom Field Value in Post Title, Post Content
- How to I make my post title link to a custom field
- Can I access Posts of custom-fields via URL?
- Best way to achieve multiple links in a post title
- Move the post title to another field
- add different custom fields value to post class if permalink or index
- automatically add custom fields to post title
- Custom Fields Permalink Plugin not observing hyphens
- Why can’t I get the correct post permalink
- Make custom user_meta as permalink for post
- Permalink structure depending on custom field
- Decouple page name from page title
- Set new url from custom post field
- WP Query Args – search by meta_key or title
- Multiple permalinks for a single post from custom field
- Custom post meta field effect on the performance on the post
- Difference between meta keys with _ and without _ [duplicate]
- Orderby meta_value only returns posts that have existing meta_key
- Can I query custom meta data through WP_Query
- Add custom objects/entities to WordPress
- Change behavior of “Insert into Post” based on attachment metadata
- Sort posts by custom field numeric value using dropdown
- How can I display all values of a custom field from posts with a certain value of another custom field or from certain post types?
- Is there a way to do multiple ordering on a multiple meta_query?
- searching in custom meta field
- How to add upload field in a custom taxonomy?
- Plugins won’t recognize my plugin’s hidden custom fields
- Store JSON in a custom field
- Custom contact form 7 select with custom values [closed]
- Best way to add custom / magic / flutter fields into RSS feed
- Setting orderby to a custom field using pre_get_posts
- BuddyPress – Hook to Update Custom Profile Fields [closed]
- Custom Fields Code not echoing whats in the value field
- Metabox will not save
- Masking Affiliate URL using $post_slug after “/go/”
- load custom fields on click
- How to wrap meta values seperated by comma in ? [closed]
- Create WordPress shortcode with php code inside
- How to create a Custom Meta Box with Name/Value Admin User Input Fields?
- Is it better practice to use ‘This Name Format’ or ‘this-name-format’ for custom fields?
- Custom Fields box in the post editor: Replace textareas with input elements
- Passing args to WP_User_Query am I using meta correctly?
- How to show a post if was published less than two hours ago?
- Define a post’s title and slug from Custom Fields
- How can you include custom post meta in search without calling each key?
- Value from custom field is not being displayed?
- Displaying page image in the footer automatically
- Hide custom column in admin template screen (Elementor) [closed]
- What is the largest value you can store in a custom field (as meta data for a post)?
- Where does this field get its value?
- ORDER BY custom field value out of where clause
- How can i retrive a text from a custom field
- List custom field values in alphabetical order without repetition
- Can’t query by meta_key
- Display MP3 as media using an URL from a custom field
- ACF: How to get users with a ACF flexible content subfield with a specific value AND layout?
- WordPress custom fields feature is missing in my installation
- Print Posts if Custom Field Value Date equal or greater than Today Date
- Is it possible to populate a custom field with content from a page
- Save all custom field data into one “master” custom field
- Convert all dates stored in custom field
- How to put forward a blog post
- Plugin or shortcode for ISBN number?
- HM CMB: Role Select
- Jquery on custom-field backend
- Display latest post depending on Meta Box content
- WP-eComerce Advance Meta Tag data in descending order [closed]
- Custom fields won’t update
- Replacing custom field with shortcode
- WPAlchemy issue when using 2 select menus with the same values inside a repeating group
- show a specific metabox dependent on the page template
- excluding posts by an ACF field in pagination
- Search & column order by meta value in admin
- Making custom meta box required (with error message if not filled in) on Gutenberg
- Is the use of many custom field not good for server?
- How can I ‘check’ the “custom fields” box from the Screen Options?
- Very large list of options for BuddyPress profile fields
- Can you generate a featured image from two images from custom fields?
- How to get all wp_posts in wordpress fetched from database
- Search fails when using the radio buttons
- Change Order of Sections Using Custom Fields
- How to add content with a filter when there’s no content in the editor
- Extra text’n’image field in a page
- Order a query by meta_value and then by post_date
- custom field functionality
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- WordPress archives by custom field and date
- Custom Field add markup to line breaks
- Use Metabox to enter Post Title
- Include custom fields into the content of a regular page
- Bypassing a Form Options
- How to implement jquery-ui autocomplete into custom fields?
- i want to send email on custom post field (job_status == 2) but it is not working
- How to create a searchable database with a single-field search box at the front end? [closed]
- Add custom fields to specific menus