You need to use save_post action along with wp_insert_post() function for this. Something like following may work.
function tnc_update_car_details( $post_id, $post, $update ) {
// If this is a revision, don't continue
if ( wp_is_post_revision( $post_id ) )
return;
$post_type = get_post_type($post_id);
// If this is not an invoice post type, don't continue
if($post_type !== 'invoice')
return;
$car_id = '1';
wp_insert_post(
array(
'ID' => $car_id,
'meta_input' => array(
'km_travelled' => '300',
),
),
);
}
add_action( 'save_post', 'tnc_update_car_details', 10, 3 );
I’ve not tested though. Please let me know the result after trying.
Related Posts:
- what is the correct way to compare dates in a WP query_posts meta_query
- How to get post content by calling ajax?
- How to show all posts of the category in wordpress?
- Get the ID of the latest post
- Limit the post for differents custom post type in the same wp_query
- How to hook get_terms() to only show count of posts that have custom meta
- Loading post content in FancyBox
- Query post types with multiple keys
- ascending order custom post type
- Get all posts WHERE custom_field is LIKE value
- Quickest way to get last or oldest post date – WP Query
- Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
- WordPress Orderby Numeric Value Not Working
- Display custom post type from dynamic custom field
- Show the same Article Available in Other Categories
- Display only one post each WEEK
- List children on child post
- Get posts between custom dates
- Get latest 3 posts from multiple CPT in one query
- Post image in WordPress not appearing on home page
- Update Post Meta for a logged in user
- Two Custom Post Types Many to Many Relationship
- Update postmeta Parent when post_status child change
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Limit the post for differents custom post type in the same wp_query
- Filter date from post meta when date is in string format
- Batch Extract Date from post title and put into ACF custom field
- List all posts in taxonomy term
- HM CMB: Post Select Field for CPT ID
- Get_post_custom not fetching value from array wordpress
- Add a form in every post and save data in post meta
- SELECT custom post type and its meta in SQL
- Save data is post using php front end
- Create a post automatically if search result has zero results
- Use WP_query to match post types based on custom field values
- Show posts from WP Custom Post Type selected from a field in a metabox
- How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
- minimize wp_query call to database
- Use WP pagination functions on a custom page template
- How to set class to “current-page” on the currently viewed single post within a CPT
- WordPress custom post type
- How to get Last post Id of custom post type in wordpress
- Edit post meta direct from post.php?
- How to create content automatically when a post is published?
- Display a post count from a custom metabox selection
- query_post causes the posts to be loaded twice on load more posts
- Query Posts From Multiple Post Types
- Return only custom post types for the page, not all
- WP Build-In Post selector for CPT
- Top 30 Songs using Custom Post Type
- Automatically add custom taxonomy when meta value gets to a set number or beyond
- I am having a problem with fetching product data in the Gutenberg block editor
- If post has custom field then display css-class
- Meta Key Value in current-user-only loop
- Archive for custom taxonomy lists all posts instead of current taxonomy
- How to check if user meta field is empty in conditional else statement
- How to set YouTube video as featured image?
- Notice: Undefined index: error and understanding wordpress
- Restrict custom post type from appearing with ?post_types=
- How to query_post custom posts within default taxonomy?
- Show custom post type filtered by category
- Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
- create parent post using wp_insert_post
- Turn on and off custom post type from admin?
- Missing Posts in Custom Taxonomy List
- Display random posts, but omit the post it is on?
- child of post type (custom)
- How do I do this with WordPress? Taxonomies?
- Page template with different page and post content
- How to use custom taxonomies to reference complex relationships?
- Disable block with taxonomies at post page
- How to implement a Google map store locator
- I would like to have different styles for my posts based on the content of each post
- is there a way to show the the post title after the image?
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- Order query using custom meta data
- Query Custom posts of same taxonomy as the post itself
- Showing posts from different categories and from custom post type
- Deleting Custom Posts & Meta Data on Uninstall
- get custom post type
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Which post does a taxonomy term belongs to?
- Conditional Query of Custom Post Type and custom taxonomy
- will post_id ever change? Can I safely use post_id for custom queries?
- List custom taxonomy specific to one custom post type
- Show a Category X’s custom post type on Category X archive page?
- Custom Post Type Query for Sidebar Doesn’t Work on Front Page
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Meta query for custom post type ignored in main query
- Changing custom type name hides the posts
- How do I create an archive page as a including metadata?
- Display Ad on Specific Categories
- Hiding posts by other users and non-logged in
- changing meta value and meta key of price field
- Posting to a Custom Post Type from front end – user generated content
- Getting meta in editor plugin, and event triggering issue
- Add custom field to Posts and sort by it
- How to duplicate entire custom post type