Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

update a posts of other custom post type

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:

  1. what is the correct way to compare dates in a WP query_posts meta_query
  2. How to get post content by calling ajax?
  3. How to show all posts of the category in wordpress?
  4. Get the ID of the latest post
  5. Limit the post for differents custom post type in the same wp_query
  6. How to hook get_terms() to only show count of posts that have custom meta
  7. Loading post content in FancyBox
  8. Query post types with multiple keys
  9. ascending order custom post type
  10. Get all posts WHERE custom_field is LIKE value
  11. Quickest way to get last or oldest post date – WP Query
  12. Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
  13. WordPress Orderby Numeric Value Not Working
  14. Display custom post type from dynamic custom field
  15. Show the same Article Available in Other Categories
  16. Display only one post each WEEK
  17. List children on child post
  18. Get posts between custom dates
  19. Get latest 3 posts from multiple CPT in one query
  20. Post image in WordPress not appearing on home page
  21. Update Post Meta for a logged in user
  22. Two Custom Post Types Many to Many Relationship
  23. Update postmeta Parent when post_status child change
  24. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  25. Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
  26. Limit the post for differents custom post type in the same wp_query
  27. Filter date from post meta when date is in string format
  28. Batch Extract Date from post title and put into ACF custom field
  29. List all posts in taxonomy term
  30. HM CMB: Post Select Field for CPT ID
  31. Get_post_custom not fetching value from array wordpress
  32. Add a form in every post and save data in post meta
  33. SELECT custom post type and its meta in SQL
  34. Save data is post using php front end
  35. Create a post automatically if search result has zero results
  36. Use WP_query to match post types based on custom field values
  37. Show posts from WP Custom Post Type selected from a field in a metabox
  38. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  39. minimize wp_query call to database
  40. Use WP pagination functions on a custom page template
  41. How to set class to “current-page” on the currently viewed single post within a CPT
  42. WordPress custom post type
  43. How to get Last post Id of custom post type in wordpress
  44. Edit post meta direct from post.php?
  45. How to create content automatically when a post is published?
  46. Display a post count from a custom metabox selection
  47. query_post causes the posts to be loaded twice on load more posts
  48. Query Posts From Multiple Post Types
  49. Return only custom post types for the page, not all
  50. WP Build-In Post selector for CPT
  51. Top 30 Songs using Custom Post Type
  52. Automatically add custom taxonomy when meta value gets to a set number or beyond
  53. I am having a problem with fetching product data in the Gutenberg block editor
  54. If post has custom field then display css-class
  55. Meta Key Value in current-user-only loop
  56. Archive for custom taxonomy lists all posts instead of current taxonomy
  57. How to check if user meta field is empty in conditional else statement
  58. How to set YouTube video as featured image?
  59. Notice: Undefined index: error and understanding wordpress
  60. Restrict custom post type from appearing with ?post_types=
  61. How to query_post custom posts within default taxonomy?
  62. Show custom post type filtered by category
  63. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  64. create parent post using wp_insert_post
  65. Turn on and off custom post type from admin?
  66. Missing Posts in Custom Taxonomy List
  67. Display random posts, but omit the post it is on?
  68. child of post type (custom)
  69. How do I do this with WordPress? Taxonomies?
  70. Page template with different page and post content
  71. How to use custom taxonomies to reference complex relationships?
  72. Disable block with taxonomies at post page
  73. How to implement a Google map store locator
  74. I would like to have different styles for my posts based on the content of each post
  75. is there a way to show the the post title after the image?
  76. How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
  77. Order query using custom meta data
  78. Query Custom posts of same taxonomy as the post itself
  79. Showing posts from different categories and from custom post type
  80. Deleting Custom Posts & Meta Data on Uninstall
  81. get custom post type
  82. Widget: Custom Post Type Post Listing Dropdown on Admin Side
  83. Allow non-logged in users to see a future post after clicking on a list of future posts
  84. Which post does a taxonomy term belongs to?
  85. Conditional Query of Custom Post Type and custom taxonomy
  86. will post_id ever change? Can I safely use post_id for custom queries?
  87. List custom taxonomy specific to one custom post type
  88. Show a Category X’s custom post type on Category X archive page?
  89. Custom Post Type Query for Sidebar Doesn’t Work on Front Page
  90. How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
  91. Meta query for custom post type ignored in main query
  92. Changing custom type name hides the posts
  93. How do I create an archive page as a including metadata?
  94. Display Ad on Specific Categories
  95. Hiding posts by other users and non-logged in
  96. changing meta value and meta key of price field
  97. Posting to a Custom Post Type from front end – user generated content
  98. Getting meta in editor plugin, and event triggering issue
  99. Add custom field to Posts and sort by it
  100. How to duplicate entire custom post type
Categories custom-post-types Tags custom-post-types, post-meta, posts, query-posts
Slugs on hierarchical taxonomies
Set display name from nickname with register process

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress