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
- Query all posts where a meta key does not exist
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Pull Two Posts Into Custom Post Type `single-cpt.php`
- Problem excluding category from get_next_post
- Compare 3 custom fields and sort by oldest
- Custom Meta Boxes – Nonce Issue – Move to trash issue
- How to use custom fields to enable sticky posts on custom post types?
- get_post_meta is returning image id
- Custom post type and body_class: Remove “blog” class
- Setting posts per page in query_posts
- How to insert content from another Custom Post type into Post?
- How to get the post type from a category id?
- Getting posts under the custom post type ui category
- Turn on and off custom post type from admin?
- JS innerhtml changing style when using AJAX
- Several post types on WP Query by tag and taxonomy
- Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Get $post->ID from a URL
- Displaying a div from an assigned meta_value when on a page
- Custom query – get_the_terms not work
- Setting Post Title via Meta Data returns Auto-draft
- why is the current page title being output?
- How to show custom field on specific custom post type posts only when filled
- Get post format
- Template code to split a post and print a custom field?
- Custom Post type registering as page post type
- Custom Posts and Posts – next_post_link and previous_post_link not working together
- Enable comments for post when comments meta box removed
- Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
- How to: Add a publish immediately button when editing custom WordPress posts?
- Extending post by email
- Checking for custom field in admin pages
- Hide title field of selected post-types on edit pages
- Custom wp-query display post only today
- Best way to fix bad count on All | Mine | Published
- Permalink for specific post type
- How to add custom PHP code in post header?
- Collect custom post in a calendar
- How To Loop Through list with Custom Post Types
- erase post excerpt limitation [×]
- Values inside a custom field to determine which category posts to display
- How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
- Advanced search form with filters for custom taxonomies and custom fields
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- show posts under custom post type with same autj
- How to automate the creation of advanced layout article/post
- Display code if title of the custom post matches title of other post