I have to save my post two times to get the variable $event_realstartdate saved. I understand why it is but don’t know how to rewrite it.
I have a textfield “event_startdate”. When the user changes this textfield, it calculates the content of a readonly textfield “event_realstartdate”.
When clicking on Update once, the readonly textfield is calculated correctly but it’s not “transfered”, so that I could use it on my page.
<input type="text" id="event_startdate" name="event_startdate" value="<?php echo $event_startdate; ?>"> <?php include( 'calculation.php' ); $event_realstartdate = $event_startdate; ?> <input type="text" readonly id="event_realstartdate" name="event_realstartdate" value="<?php echo $event_realstartdate; ?>">
if(isset($_POST['event_startdate'])) {
update_post_meta($post_id, 'event_startdate', esc_attr( $_POST['event_startdate']) );
}
if(isset($_POST['event_realstartdate'])) {
update_post_meta($post_id, 'event_realstartdate', esc_attr( $_POST['event_realstartdate']) );
} this reply was nonsense
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
try “disabled” instead of “readonly”
no then it doesn’t work anymore. There’s no problem with readonly.
The problem is that the correct content in the readonly field is only available after saving the first time. After saving the second time, the variable gets the content of the readonly field.
Everything should be done when saving the first time
Any Ideas?
Hi, thank you for helping. I already tried it similar to your version:
if(isset($_POST['event_startdate'])) {
update_post_meta($post_id, 'event_startdate', esc_attr( $_POST['event_startdate']) );
include( 'recurring-calculation.php' );
$_POST['event_realstartdate'] = $_POST['event_startdate'];
update_post_meta($post_id, 'event_realstartdate', esc_attr( $_POST['event_realstartdate']) );
}
But I always get this error message when updating the post:
Warning: Cannot modify header information - headers already sent by (output started at C:\iwpserver\htdocs\wordpress\wp-content\themes\eventix\includes\recurring-calculation.php:3) in C:\iwpserver\htdocs\wordpress\wp-includes\pluggable.php on line 881
This error message is only because of the include function. Doesn’t matter what I write in this php file (even if it’s empty). If I remove this include, it would work.
Is there another way instead of posting the whole php file in my metaboxes.php ?
edit.
