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

Empty meta-box returns publishdate if no value is set?

I’m half asleep here so correct me if I am wrong here but it looks to me like you are saving the publish date of the post each time you save the post,

$wr_event_end_date = isset($_POST['wr_event_end_date']) ? $_POST['wr_event_end_date'] : '';
$event_end_date = new DateTime($wr_event_end_date);
update_post_meta($post->ID, "event_end_date", $event_end_date->getTimestamp());

This -> $event_end_date->getTimestamp() being the culprit.

So regardless of your variable $wr_event_end_date value being set or not, your meta value is being assigned via getTimestamp() because firstly there is no conditional statement that checks for the existence of your,

$_POST['wr_event_end_date'] 

which if FALSE will instead revert to '' (no value) which is then passed to your

new DateTime($wr_event_end_date);

Secondly, because

new DateTime( //is now empty here );

your

getTimestamp()

returns the current time stamp of the post.

UPDATE

You should still use the text_date custom field, example:

array(
    'name' => 'Test Date Picker',
    'desc' => 'field description (optional)',
    'id'   => $prefix . 'test_textdate',
    'type' => 'text_date',
),

…instead of using a timestamp especially if you have no reason to use a timestamp other than to convert it back to a regular date format because WordPress has inbuilt functions for handling date and time formatting.

Here is an example;

global $post;
$text = get_post_meta( $post->ID, '_cmb_test_textdate', true );
$text = date('d F Y', $text); 
echo $text;
    //prints 25 September 2012 for example

I’ve made sure to test this library to ensure it is in fact outputting results correctly and it sure is.

Related Posts:

  1. Detect meta value changes when post is updated (post_updated)
  2. Displaying Meta Box Image
  3. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  4. Populate Custom Fields in a Custom Post Type?
  5. How to check if user meta field is empty in conditional else statement
  6. A better way to add a meta box to custom post types
  7. create custom meta box with default value
  8. How can I output WPAlchemy repeating fields meta values in my page template?
  9. Add a class to post_class if more than one post shares same meta_value_num
  10. Add a meta field to the list of results for a custom post type
  11. Custom Post Type meta data getting deleted on bulk editing taxonomies
  12. Delete custom post type metadata without deleting the post in admin area
  13. Update Post Meta for a logged in user
  14. Found 2 elements with non-unique id (#_ajax_nonce) and (#_wpnonce)
  15. Plugin – Combine Meta Box Input Fields into single saveble record
  16. Two Custom Post Types Many to Many Relationship
  17. get_post_meta not working on publishing
  18. Meta Query Filtering not working on Custom Meta Box using Radio Buttons
  19. How do I set all of a particular post meta to a value within the custom post type I’m in?
  20. Grouping metadatas into one
  21. Metabox not show in categories custom post type cmb2
  22. Repeatable Fields Metabox with Textarea (or wp_editor)
  23. How to use TinyMCE Editor for one of my custom post meta field?
  24. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  25. Show Custom Post Type meta boxes only on Page Edit
  26. Cannot save CPT meta box
  27. Adding Page Templates to post but it ignored it
  28. Importing Data from a Non-WordPress database, into WP
  29. Permalinks: custom structure for taxonomy – tags?
  30. Can’t publish custom post type – “You are not allowed to edit this post.”
  31. Custom fields for custom post type
  32. Custom “radio button meta box” not saving correctly
  33. Meta Data for Custom Post Type not saving
  34. Add additional field to custom post_type
  35. Custom Post Meta from custom metaboxes is randomly being deleted
  36. Check if post with same meta value exists
  37. Add a custom meta box for client to order CPT posts how they want
  38. Submitting Custom Post Types with custom fields from Front-end form
  39. Display Repeatable Meta Box Content
  40. Displaying a div from an assigned meta_value when on a page
  41. How to Echo Metadata Value in Currency Format
  42. Issue on Working with Metabox – Checkbox to enable Sale Items
  43. delete_post_meta() for whole CPT / multiple posts?
  44. How to get specific post meta by title or id
  45. What do the numbers mean at the end of add_action(‘save_post’)…?
  46. A meta box (in a custom post type) with two different type of fields
  47. Why do I have to press the “Update” button twice to save my meta box values?
  48. Values from meta-box not on $_POST
  49. Sort custom post type by most current date picker
  50. Custom post type suddenly stoped working after WordPress 5 update
  51. copy images from custom field to another custom field
  52. How to show custom field on specific custom post type posts only when filled
  53. Reusable metabox backend and frontend
  54. Cannot obtain custom meta information
  55. Get custom term meta problem on single post type
  56. Display custom meta on page that has been check in custom post type
  57. Meta box data is saved but NOT displayed in the meta box text field. Why?
  58. How to call a post’s metadata in shortcode.php?
  59. How can I modify a custom post type and custom page template for a child theme if all content seams to be handled by theme’s ‘native’ plugin?
  60. Save Metabox Custom Field Value
  61. Meta box data not saving
  62. WP_Meta_Query object with conditionals
  63. Related posts meta_query CPT
  64. Meta box with front-end styling
  65. Sanitaizing Select Optin For Custom Post Type Metabox in WP
  66. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  67. Cannot Save MetaBox Data in Custom Post Type
  68. Adding an extra parameter [string] to my posts’ permalink?
  69. delete duplicate meta_value with same post_id
  70. Search CPT Title AND Meta
  71. updating one custom meta field only
  72. Problem On Retrieving Post Meta Data on Custom Column [closed]
  73. Function to return values from metabox
  74. Saving metabox keys and storing values as array
  75. Custom Post Type Meta Box Text Input Field Won’t Save When Blank
  76. how to compare different timestamps in wp-query for events custom post types?
  77. Filter search posts by post meta?
  78. Custom Meta Box with variable number of fields
  79. Custom fields for post or terms which don’t update on post update
  80. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  81. How to keep custom post type related information
  82. How to avoid duplicate posts queried from custom meta?
  83. Custom Metabox Info Not Saving
  84. How can I add a meta[] to my custom post type and search by term with the Rest API?
  85. Show posts from WP Custom Post Type selected from a field in a metabox
  86. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  87. Where is get_post_meta value located?
  88. PHP Warning with Custom Fields
  89. Custom meta fields not showing up in WP_Response Object via custom endpoint
  90. Problem with multi checkboxes value in metabox?
  91. Get meta values from parent post and save in child post
  92. How to Disable option of meta field if that option is selected for any other post in custom post type?
  93. Simple Data picker meta box
  94. Metaboxes in Loop
  95. Add more custom fields when creating a new custom post type
  96. check_admin_referer not working in custom meta box for custom post type
  97. Custom meta box data not saving
  98. How do I extract the contents of a CPT’s custom field for all posts?
  99. Collect custom post in a calendar
  100. Query events post type after current date and timezone
Categories custom-post-types Tags custom-field, custom-post-types, events, metabox, post-meta
How to do more than one verify_nonce in one function?
How to show beneath posts the full category path?

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