Here in WordPress.org you have a example to do that:
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_insert_post
Look also here to see when it modified
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
Regards.
Related Posts:
- Get post with multiple meta keys and value
- Get posts for custom post type with WP_Query
- Custom Post type in separate database table for syncing
- Why would WordPress use ‘attachment’ in a custom post type’s query string?
- Unregister post type from child theme
- Creating Photo Gallery System with Custom Post Type
- Custom Taxonomies Terms as Post Title for Custom Post Types upon Publishing
- Custom Post Type With Different Views
- How to get term link that crosses different custom post types?
- Custom post type Admin Page
- One of two Custom Post types not being registered
- How to set individual capabilities on a taxonomy? Or how to re-register an existing taxonomy?
- Set post title from two meta fields
- Where to put archive-{post-type}.php
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Correct way to use a form to to filter custom posts by taxonomy terms?
- Using Custom Templates for Custom Post Types for the Genesis Theme Framework?
- WordPress custom post type category pagination 404 Error
- Custom Taxonomy order by Custom Field
- Custom post types – non-visible title and how it affects URL
- Custom Post Type: How to display all of same taxonomy?
- Custom post-type in root directory, blog posts in subdirectory
- How can I include meta box content when searching?
- “More” span making trouble
- List all custom post type posts from a given category?
- Get all posts WHERE custom_field is LIKE value
- Filter home_url for custom post type
- How to rename image at uploading on specific plugin or post-type in WordPress
- Loop on front-page.php
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Create custom post type on successful woocommerce order [closed]
- How to create a json API for my custom post type
- Display custom post type in hierarchical order with get_terms
- the_title filter returning wrong post type
- Dynamically creating custom post type items and updating them
- Creating a Page to View the List of Posts for a Custom Post Type?
- Am unable to reset a query properly
- Registering different Post Formats for Blog Post and CPT
- Custom post type (with parent-child relationship) singular page with pagination
- Creating a navigation menu of all posts of a custom post type and their children posts?
- Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
- Filter custom posts using auto populated dropdown selectors
- A simple script to allow sorting of custom posts in admin?
- Update post meta not working in transition_post_status
- Display Custom Toxonomy In WordPress and theme Widgets category selection dropdown list
- How to change the post type a theme shows by default?
- URL rewrite add author as base
- Update database from Quick Edit according to Checkbox state of Custom Post Type
- Custom Post Type slug same as page name
- manage_edit-{post_type}_sortable_columns sorts, but wrong!
- Convert comments to Custom Post Type
- Is there any way to add a “custom field” to the CPT archive page?
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- WebP Fallback for Inline Background Image in Style Attribute
- Post to Top in Array
- Detect inside a custom query the kind of post type to assign custom classes
- Checking if looped item has a parent inside a shortcode
- Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
- Query all post and CPT from 2 specific taxonomies AND by ACF custom field
- Check if user has custom post published redirection on WordPress
- Custom post type permalink returns 404 when set to private
- Assigning alternate single-{cpt} template based on blog_id in multisite
- How can i add multiple variable to a !== query
- Dynamic pages for linked categories and content
- Create Custom Post type that uses Page.php template
- Displaying a custom post type using get_template_part into a specific layout
- How can I make custom static widgets/areas on my homepage?
- Add custom post type taxonomy tag to article class
- Custom Taxonomy dont save in a frontend form for post a custom post
- Plugin needed to allow subscribers to post articles on the front end without admin approval [closed]
- Page template that uses lightbox to display post images
- Setting Parent Page to Post
- Custom Post type dont use custom page template (slug is not right)
- Get the taxonomy value in the post loop inside the archive page
- Custom Post Type & Taxonomies – Rewrite
- Custom Post Type and Structure Question
- Custom Taxonomy Page
- Do not show child pages within a file page
- Change CPT permalink to use the category
- Custom post types & Pages hierarchy – Error 404
- custom post type section selector
- Previous/Next custom post links within custom taxonomy
- wp_dropdown_pages doesn’t allow me to select more than one custom post type
- Override “Parent” input for custom taxonomy
- How to develop custom URL redirection
- disabel for custom post Auto Upload Images
- Function not pulling image or text from custom post type
- Questions on WordPress Codex Concept
- Custom Post Type Archive Links Not Working
- Why is this custom post type defaulting to archive.php?
- Custom post types permalinks not working
- How do I ensure custom post type information is displayed in correct order?
- Tag-post relationship problem
- Rewrite rules for using the same base slug for multiple content types
- MF2 and qTranslate problem with custom post types post titles [closed]
- How do I filter a custom post type loop by a field?
- How to order different custom post type in category or tag template page?
- Custom Post type as Taxonomy
- How to manage wordpress knowledge base/wiki/posts collections
- Add post id to url instead of WordPress default -2 suffix