You are using wrong variable on the following line:
$data['post_title'] = $post_title;
you should use $event_title in $post_title as following:
$data['post_title'] = $event_title;
Also Get Post ID from $postarr parameter.
Updated Code :
function set_event_title( $data , $postarr ) {
if($data['post_type'] == 'events') {
$event_date = get_post_meta($postarr['ID'],'event_datetime',true);
$event_venue = get_post_meta($postarr['ID'], 'venue_name' , true);
$event_title = $event_venue . ' - ' . $event_date;
$post_slug = sanitize_title_with_dashes ($event_title,'','save');
$post_slugsan = sanitize_title($post_slug);
$data['post_title'] = $event_title;
$data['post_name'] = $post_slugsan;
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'set_event_title' , '10', 2 );
For more information on this filter visit this page.
Related Posts:
- How I check if the same post slug has not been used before publishing?
- Custom Post Type with Custom Title
- Using a Custom Field instead of original title field but only for Custom Post Type
- Using several custom fields as custom post title
- Set a maxlength for the title input in a custom post type
- Change “Enter Title Here” help text on a custom post type
- How do I set the default admin sort order for a custom post type to a custom column?
- How can I change the admin search posts fields?
- Development of a WordPress Search Plugin – Best Practices
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- WordPress 4.4+ : How to revision CPT + metadata
- Query custom post type by custom field
- Adding meta values to permalink
- Filter a custom field based on selection of another custom field (ACF) [closed]
- How to get custom metabox image field?
- Getting Bootstrap accordion working in WordPress loop with custom post type (collapsing issue)
- Custom post type or just use custom fields
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- set and unset the custom field value
- How to programatically set the post title of a CPT on wp-admin
- How to Sort by Date When Using d-m-Y Format
- Metabox saving values
- WP insert post PHP function dynamically generated Custom Fields
- Multiple information using custom post type
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- How to add custom fields to admin UI and REST API response?
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- Before Delete Post
- Display custom post on home page based on a metabox selection
- Sort posts based on multiple custom fields
- Related links – from other sites
- 1 day after custom date change post status to draft
- WP_Query that filters based on custom relationship field
- Filtering by Post Meta Custom Fields – Performance
- WP Query—Relationship between two custom post types and their fields
- Why do I lose the content of meta boxes when I leave the page?
- Remove wrong dashes from get_the_title()
- Plugin for custom posts and fields [closed]
- Populate Custom Fields in a Custom Post Type?
- How to change post featured image using a custom field of category?
- Returning a list of custom post types excluding those without a specific meta_value
- How to check if user meta field is empty in conditional else statement
- How to stick custom post at the top in search results
- Custom post type content using custom fields without template
- Plugin – Combine Meta Box Input Fields into single saveble record
- Callback to custom field is not working in WordPress REST API
- How to render a custom post type template with custom fields using shortcode
- Get Posts by multiple custom fields is not working
- Cannot save CPT meta box
- Custom Meta Title for Custom Post Type
- custom comments form for custom post type
- Custom post type’s extra fields – how to handle?
- Enable Custom Fields For Custom Post Type When CPT Created Using Plugin
- Submitting Custom Post Types with custom fields from Front-end form
- post_per_page ignored in WP_Query
- Address as a content type post
- finding and using post type fields in WordPress
- Sort custom post type by most current date picker
- Should Custom post types and fields be in the theme files or in a custom plugin packed into the theme?
- Remove default WYSIWYG editor without removing custom fields editors
- Display custom post type for specific user
- Display custom meta on page that has been check in custom post type
- How do I update_post_meta() or add_post_meta() with an AJAX call
- Filtering Custom Post Type by Comparing Date and Two Meta Keys
- How to prevent meta data from being edited in a post?
- Automatically add a character to field in edit post page
- Add the custom post term to the custom post title
- Change Post Meta via AJAX from the posts list table
- How to keep a record of changes to a custom field?
- Saving metabox keys and storing values as array
- Mandatory field in Custom post
- Update value inside array update_post_meta
- How to store the third party script with HTML code in the wordpress custom input field?
- WP Query from two Custom Post type fields as statement
- How To Read Read Custom Post Type Data in Headless CMS Mode
- Filter custom post type admin list by custom meta column, where the column is another custom posts meta value
- How to upload an image to a custom post type
- How to display custom field in product description?
- when looping through custom post data not appearing
- Add custom template ‘sub-page’ to Custom Post type?
- Where is get_post_meta value located?
- Adding a Section for Visitors
- Automatic Set Category For A Custom Post Type
- Sort loop by custom field from different post type
- Meta_query by date for Events archive
- WordPress loop, show only one post per custom field
- Generate slug and meta data if meta field is empty
- one get_posts to return a number of custom posts for each meta value
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- Custom Post Type as invoice or order template
- WP_Query get posts where post_name is empty
- Get result from Custom Field in Custom Post type
- Make each Value of custom field show related posts when clicked
- Advanced search form with filters for custom taxonomies and custom fields
- Querying meta values within an array
- Creating entries with image attachements within posts and managing them in a list
- How to Create a Frontend Html-list Editable in the Backend?
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- How to get lowest price from custom fields of posts
- Custom Sort Order for Custom Post Type Taxonomy