As soon as you hit “Add New” and the new post pages starts to load, WordPress inserts a mostly blank post template into the database. Periodically after that you get auto-saves. You don’t want either. You will need to add additional conditions to prevent your code from running in those circumstances. Something like this in addition to your $data['post_type'] == 'matches' && $data['post_title'] == '':
if (
(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
|| (defined('DOING_AJAX') && DOING_AJAX)
|| ($p->post_status === 'auto-draft')
) {
Personally, I think you’d be better off hooking into a different, more specialize hook, like publish_post or a post status transition hook.
Related Posts:
- Advanced search form with filters for custom taxonomies and custom fields
- Meta query with boolean true/false value
- Get post with multiple meta keys and value
- Custom field values deleted when trashing custom post type
- How to get all custom fields of any post type
- Update CPT meta data using REST API
- How do I remove all the metaboxes for a custom post type?
- Custom Queries: Joining On Meta Values From Two Custom Post Types
- Gutenberg how to make attribute to save to meta
- Get all posts from custom post type and insert in select input as metabox
- Custom Post Type: Set post_title equal to a custom post type field
- I can’t set meta_key in my custom post type query
- WordPress Admin Panel search posts with custom post meta values along with title
- How to Update post status using meta data in Custom post TYpe
- Rest Api v2 orderby meta_key in custom post type
- bulk Update post_meta with default values
- How can I include meta box content when searching?
- Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
- Add Post Url to Manage Edit Screen
- Display all custom post type posts and order them by an optional meta_key
- How can I get_post_meta() in the most efficient way?
- need advice on how to do a lists using custom post types – taxonomy vs postmeta
- how to interconnect custom post types?
- Custom Post Status Transition Issues With Get Post Meta
- List all images from a single post meta value
- orderby in custom WP Query does not work
- Show the same Article Available in Other Categories
- how to delete all users and posts based on ‘user_meta’?
- Meta Key Value in current-user-only loop
- How to set YouTube video as featured image?
- Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
- How to implement a Google map store locator
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- How do I create an archive page as a including metadata?
- Update Post Meta for a logged in user
- How to duplicate entire custom post type
- Two Custom Post Types Many to Many Relationship
- get_post_meta not working on publishing
- get_post_meta returning no value in custom post type alert email
- Update postmeta Parent when post_status child change
- WordPress request fiter order by related post’s post_title
- Update database from Quick Edit according to Checkbox state of Custom Post Type
- Getting thumbnails of a custom posts featured images in a page-templates metabox
- Remove Post Custom Meta Box
- Show future events based on custom field AND order by date
- If Post Meta Equals Current Title Conditional Advanced Custom Fields
- create custom meta box with default value
- Meta data (Tags and Categories) for Custom Posts not showing.
- Display different information of a custom post type
- delete_post_meta() for whole CPT / multiple posts?
- How to get specific post meta by title or id
- How can I display a drop-down select of Post Names
- how to show records that don’t have custom meta value
- $post->post_meta not pulling any post in wordpress/php
- WP_Query of custom post type sorted by meta_key has unexpected results
- Cannot obtain custom meta information
- Get all metadata for a given custom post type
- Advanced custom field – posted fields from custom post type
- delete duplicate meta_value with same post_id
- Search CPT Title AND Meta
- Add a class to post_class if more than one post shares same meta_value_num
- Function to return values from metabox
- Add a meta field to the list of results for a custom post type
- Empty meta-box returns publishdate if no value is set?
- Filter search posts by post meta?
- Custom fields for post or terms which don’t update on post update
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Add a form in every post and save data in post meta
- How to use multiple Meta Field from CPT as Post permalink
- Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
- Attaching more than 1 parent (Post) to a media file
- Use WP_query to match post types based on custom field values
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- How to get post by meta value
- Get meta values from parent post and save in child post
- How do I get all authors posts of a custom post type outside loop
- How to Disable option of meta field if that option is selected for any other post in custom post type?
- How to get post detail based on URL of the post
- Stored meta from attachment, video length?
- Custom post type meta fields missing on save_post_type
- Linking posts together with Advanced Custom Fields “both ways”
- Order posts by meta value hiding posts instead of re-ordering
- custom search results – order results differently by post type
- How to get Current week and current date record wp query
- get_post_meta for Custom Post Type ( CPT )
- Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
- How to add post reference field to a plugin?
- Custom Post Type meta oembed html output resulting in WSoD
- Add auto increment value to custom meta
- Create action running on trashed_post hook to modify post_meta value
- Random meta field from specific custom post type
- Custom Form Data save after Login User
- Changing to different post type maintains the redirection?
- Post Meta for Custom Post Types
- How do I add the “orange counter” next to a Custom Post Type?
- CPT meta values intermittently return empty
- Quering a post object based on another related post object
- rest_api_init is not getting invoked inside a Class