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

Custom Post Status Transition Issues With Get Post Meta

The following worked for me. I hooked my meta saving and retrieving to the same action (post_transition_status), but with different priorities.

//Save Your Custom Meta Meta, but hook it to transition_post_status instead of save_post, with a priority of 1
function save_yourpost_meta(){
  global $post;
      if($post -> post_type == 'your_post_type') {
          update_post_meta($post->ID, "your_meta_key", $_POST["your_meta_key"]);
      }
  }
add_action('transition_post_status', 'save_yourpost_meta',1,1);


//Then retrieve your custom meta only when the post is saved for the first time, not on updates. Hooked to the same action, with a lower priority of 100

function get_meta_on_publish($new_status, $old_status, $post) {
if('publish' == $new_status && 'publish' !== $old_status && $post->post_type == 'your_post_type') {
  //Get your meta info
  global $post;
  $postID = $post->ID;
  $custom = get_post_custom($postID);
  //You have your custom now, have fun.

  }
}
add_action('transition_post_status', 'get_meta_on_publish',100,3);

I hope this helps!

Related Posts:

  1. Query all posts where a meta key does not exist
  2. what is the correct way to compare dates in a WP query_posts meta_query
  3. Admin Area Custom Type Search By Meta Fields Without Title & Content
  4. How can I filter posts by post_parent in the admin?
  5. How to create a mini directory in WordPress?
  6. Detect meta value changes when post is updated (post_updated)
  7. Search everything (posts, pages, tags, cpt, meta)
  8. Permalinks using event date (year & month) instead of publication date
  9. Compare 3 custom fields and sort by oldest
  10. Reason action hook won’t work with update_post_meta from frontend form? Alternative?
  11. Can’t sort order of wp_query with 2 meta keys
  12. How to get source of custom meta image?
  13. update a post meta from a single table cell TablePress
  14. update custom post type meta from a shortcode
  15. Custom Meta Boxes – Nonce Issue – Move to trash issue
  16. Displaying Meta Box Image
  17. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  18. Displaying custom posts only if custom meta box’s date is not expired
  19. Displaying Metabox value (custom post type taxonomy)
  20. get_post_meta is returning image id
  21. Custom Post Type, Saving Multiple Checkboxes
  22. get_template_part() – post-meta not working?
  23. Create a random unique 6 digit number as custom field for custom post type
  24. Export entries and multiple custom field meta to .csv?
  25. Metadata for a taxonomy – is there any WordPress way of doing this?
  26. Populate Custom Fields in a Custom Post Type?
  27. Insert Multiple Post with Same Publish Button
  28. Update CPT post meta with update_post_meta and cron job
  29. Custom meta box data array: foreach not working correctly?
  30. How to check if user meta field is empty in conditional else statement
  31. Get posts between custom dates
  32. A better way to add a meta box to custom post types
  33. Should wp_postmeta meta_key always be unique for a given post_id?
  34. How do I set all of a particular post meta to a value within the custom post type I’m in?
  35. Metabox not show in categories custom post type cmb2
  36. Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
  37. Importing Data from a Non-WordPress database, into WP
  38. List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
  39. Can’t publish custom post type – “You are not allowed to edit this post.”
  40. Filter date from post meta when date is in string format
  41. Get only used meta_values
  42. Get $post->ID from a URL
  43. Displaying a div from an assigned meta_value when on a page
  44. Setting Post Title via Meta Data returns Auto-draft
  45. Values from meta-box not on $_POST
  46. Returning a custom content types with meta values
  47. Custom post type suddenly stoped working after WordPress 5 update
  48. Batch Extract Date from post title and put into ACF custom field
  49. How to show custom field on specific custom post type posts only when filled
  50. How to handle this specific case of custom post type?
  51. is_main_query() never called on WP 4.4
  52. How can I output WPAlchemy repeating fields meta values in my page template?
  53. Meta box data not saving
  54. Related posts meta_query CPT
  55. Meta box with front-end styling
  56. How can I get some of a posts meta data whilst it is still inserting?
  57. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  58. Cannot Save MetaBox Data in Custom Post Type
  59. Getting WordPress to store 0 values for custom post type meta
  60. best way to use custom taxonomy, post type and meta in a job system
  61. Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
  62. How to order custom posts by one of the custom fields value, ‘date’?
  63. Hide title field of selected post-types on edit pages
  64. WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
  65. Custom Post Type meta data getting deleted on bulk editing taxonomies
  66. How to create review point system for CPTs (many-to-many relationship)
  67. After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
  68. Get_post_custom not fetching value from array wordpress
  69. How can I write a function that would update any missing specific post metadata?
  70. SELECT custom post type and its meta in SQL
  71. Save data is post using php front end
  72. How to keep custom post type related information
  73. Custom attachment function not working in v5.4.2?
  74. Can’t save meta box data in WordPress using custom post types
  75. Creating a custom post type upon registration for a specific user role
  76. How to sort by multiple values in a nested WP_Query
  77. How can I use a custom template to load custom post type posts based on a post_meta value
  78. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  79. Custom Function to redirect singular post if specific meta field is empty
  80. Saving Child Terms on front end not setting parent
  81. Custom post type: “transition_post_status” action get title and other fields
  82. update a posts of other custom post type
  83. How do I extract the contents of a CPT’s custom field for all posts?
  84. Collect custom post in a calendar
  85. Delete custom post type metadata without deleting the post in admin area
  86. Order by post meta value gets random results
  87. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  88. meta query always fails even if data is correct
  89. Values inside a custom field to determine which category posts to display
  90. Display a post count from a custom metabox selection
  91. How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
  92. Rich Custom Field for Custom Post type not saving
  93. Custom post type submenu sorted by specific meta_key & meta_value
  94. Advanced search form with filters for custom taxonomies and custom fields
  95. Post AND page parameter for WP function
  96. How to display Author Profile based on Custom field value
  97. Automatically add custom taxonomy when meta value gets to a set number or beyond
  98. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  99. Check for custom field value in different post type than current one and do something
  100. I am having a problem with fetching product data in the Gutenberg block editor
Categories custom-post-types Tags custom-post-types, post-meta
Files automatically added
Shortcode parsed incorrectly because of heredoc

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