Forum Replies Created
Viewing 1 post (of 1 total)
-
AuthorPosts
-
December 13, 2023 at 11:32 am in reply to: WordPress ACF Datepicker Field Update To Todays Date But Keep Time At Value In Post #9923tobygParticipant
So this seems to work for a single post ID, how can I generalise out for all posts in a specific custom post type?
function update_acf_datetime_field() { // Assuming you have the post ID and your ACF field name $post_id = 120; // Replace with your actual post ID $field_name = 'date_time'; // Replace with your actual ACF field name // Get the current value of the ACF datetime field $current_datetime = get_field($field_name, $post_id); // If the field has a value, update only the date part to today if ($current_datetime) { $today_date = date('Y-m-d'); $updated_datetime = $today_date . substr($current_datetime, 10); // Preserve the time part update_field($field_name, $updated_datetime, $post_id); } } // Call the function to update the ACF datetime field update_acf_datetime_field();
-
AuthorPosts
Viewing 1 post (of 1 total)