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

Publish and save specific postmeta to a filtered post_type

Do the check inside the callback. save_post will pass you both the post ID and the post object:

do_action('save_post', $post_ID, $post);

So…

function save_my_meta_box_to_postmeta($post_ID, $post) {
  if ('yourtype' === $post->post_type) {
    echo '<pre>';
      var_dump($post_ID,$post);
    echo '</pre>';
    die;
  }
}
add_action('save_post','save_my_meta_box_to_postmeta',1,2);

You may want other conditionals as well like !DOING_AJAX, for example.

Related Posts:

  1. Correctly delete posts with meta and attachments [duplicate]
  2. Storing revisions of metadata for custom post type
  3. Custom Post type – how to get checkbox to update meta field to null
  4. How do I Paginate Search Results for Custom Post Types?
  5. Ordering posts having multiple post-meta date fields
  6. Custom Post Type with Input fields to seperate table on database.
  7. How to programmatically create a connection with [Plugin: Posts 2 Posts] on cpt publish?
  8. How Can I save multiple records in same meta key?
  9. Permalinks using event date (year & month) instead of publication date
  10. How Do I Use WP_Query to Run This Database Query as Search Result?
  11. Creating a custom post type upon registration
  12. Reason action hook won’t work with update_post_meta from frontend form? Alternative?
  13. Showing Meta Data for Custom Post Types?
  14. Having trouble with custom post type / meta box
  15. Query for posts from any post type but only add instock products
  16. update custom post type meta from a shortcode
  17. Custom post type category not displaying in custom post type
  18. How to make custom post meta wp_editor translatable?
  19. How to keep a check box in custom meta box for custom post type checked by default for add new post?
  20. How to add multiple featured image in meta box in post editor?
  21. Show metabox in custom-post-template depending on taxonomy term?
  22. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  23. update_post_meta() whenever custom post type is updated
  24. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  25. Using date stored as custom field to filter posts displayed in admin
  26. Meta Box Only in CPT Edit Page, Not in Add New
  27. get_template_part() – post-meta not working?
  28. Count posts with specific term_meta
  29. Custom search for custom post meta with pre_get_posts interferes with WP search
  30. My theme saves their custom post type’s metadata as a serialized array, how to access the keys?
  31. Does WordPress limit the length of slug names for Post Meta or Terms?
  32. Populate Custom Fields in a Custom Post Type?
  33. Insert Multiple Post with Same Publish Button
  34. Custom meta box data array: foreach not working correctly?
  35. Undefined Variable – Custom Post Type Meta
  36. How to check if user meta field is empty in conditional else statement
  37. Post image in WordPress not appearing on home page
  38. changing meta value and meta key of price field
  39. Posting to a Custom Post Type from front end – user generated content
  40. Getting meta in editor plugin, and event triggering issue
  41. Should wp_postmeta meta_key always be unique for a given post_id?
  42. Metabox not show in categories custom post type cmb2
  43. Can’t publish custom post type – “You are not allowed to edit this post.”
  44. Custom fields for custom post type
  45. Filter date from post meta when date is in string format
  46. Get only used meta_values
  47. Is there a way to exclude posts based on meta_values?
  48. Submitting Custom Post Types with custom fields from Front-end form
  49. Get $post->ID from a URL
  50. Displaying a div from an assigned meta_value when on a page
  51. Setting Post Title via Meta Data returns Auto-draft
  52. How to Echo Metadata Value in Currency Format
  53. Filter posts by tax (dropdown) and meta value
  54. Batch Extract Date from post title and put into ACF custom field
  55. How to handle this specific case of custom post type?
  56. Save CTP post meta different values each day without overwriting previous values
  57. get_post_meta returns NULL in front-end, but correct result in back-end
  58. Meta box data is saved but NOT displayed in the meta box text field. Why?
  59. How to call a post’s metadata in shortcode.php?
  60. Echo custom post meta from options array
  61. Value of post meta dropdown is not showing in WordPress
  62. Sanitaizing Select Optin For Custom Post Type Metabox in WP
  63. HM CMB: Post Select Field for CPT ID
  64. Getting WordPress to store 0 values for custom post type meta
  65. Problem Saving Custom Post Type Meta Values
  66. Should I use a custom taxonomy or custom post type for grouping a list of panels associated with a group of tests?
  67. Get_post_custom not fetching value from array wordpress
  68. Save data is post using php front end
  69. Creating a custom post type upon registration for a specific user role
  70. How to sort by multiple values in a nested WP_Query
  71. Peepso: Add extra data field (custom post meta) to postbox
  72. Where is get_post_meta value located?
  73. How do I create a customised table list of a custom post type (in the admin area)?
  74. Change picture attachment meta of all occurrences of a picture
  75. Unknown Post Meta Records
  76. add action save post type and update post meta woocommerce
  77. get_post_meta not working with variable as a post_id for dynamically get the postid
  78. How to save post_status using action save_post?
  79. Custom post meta box as a sub form
  80. Metaboxes in Loop
  81. Add more custom fields when creating a new custom post type
  82. Custom meta box data not saving
  83. Collect custom post in a calendar
  84. Storing data in a multidimensional array from dynamically generated foreach loop
  85. Disable Facebook Comments Automatically On CPT
  86. Problem with ‘save_post’ hook not running
  87. WordPress custom post type
  88. Edit post meta direct from post.php?
  89. Howto: use existing post_meta as options for a different metabox (checkboxes or list)
  90. Values inside a custom field to determine which category posts to display
  91. How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
  92. Change the contents of a dropdown through the admin panel?
  93. Advanced search form with filters for custom taxonomies and custom fields
  94. Top 30 Songs using Custom Post Type
  95. Advice Needed for Post Meta Database Efficiency
  96. Querying meta values within an array
  97. why get_post_meta is returning 0?
  98. Save post_parent in a custom post type
  99. Update an existing post in a custom post type
  100. getEntityRecords/useEntityRecords: How to use CPT metadata?
Categories custom-post-types Tags custom-post-types, post-meta
Load custom script on a single template
Dynamic image crop in WP 3.0+?

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