Home › Forums › General Issues › Hook/Filter to edit the timestamp after user has selected a date and time › Reply To: Hook/Filter to edit the timestamp after user has selected a date and time
Update: So I have found this http://www.advancedcustomfields.com/resources/acfsave_post/.
I am hooking into it, but the date isn’t actually being written to the database. Not sure why not. Here is my code:
function updateSeminarTime( $post_id ) {
// bail early if no ACF data
if( empty($_POST['acf']) ) {
return;
}
// array of field values
//$fields = $_POST['acf'];
// specific field value
$post = get_post( $post_id );
$expertId = $post->post_author;
$userTimeZone = getTimeZone($expertId);
$userTimeZoneOffset = get_timezone_offset($userTimeZone,'UTC');
$seminarDate = $_POST['acf']['seminar_date'];
$seminarDate = strtotime($seminarDate);
$seminarDate = $seminarDate + $userTimeZoneOffset;
$seminarDate = date('m/d/y h:mm tt',$seminarDate);
$_POST['acf']['seminar_date'] = $seminarDate;
}
// run before ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'updateSeminarTime', 1);
I’m wondering if I am writing the format wrong. BTW I have tried with date() and formatting it to a string and also just as a UNIX timestamp.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.