[Special Summer Sale] 40% OFF All Magento 2 Themes

Cart

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • tobyg
    Participant

    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();
    
Viewing 1 post (of 1 total)