Cell format: Display timestamp value as friendly date

| 0

For example, our posts have one meta field with a timestamp and the spreadsheet shows the timestamp like this:

We can use the following code to display the values as friendly dates, so we can view, edit, and save the column using friendly dates:

add_filter('vg_sheet_editor/provider/post/update_item_meta', 'wpse_expiration_filter_cell_data_for_saving', 10, 3);
add_filter('vg_sheet_editor/provider/post/get_item_meta', 'wpse_expiration_filter_cell_data_for_readings', 10, 5);
  
function wpse_expiration_filter_cell_data_for_readings($value, $id, $key, $single, $context) {
  if ($context !== 'read' || $key !== '_expiration-date' || ! $value) {
    return $value;
  }
  
  $value = get_date_from_gmt(gmdate('Y-m-d H:i:s', $value ));
  return $value;
}

function wpse_expiration_filter_cell_data_for_saving($new_value, $id, $key) {
  global $wpdb;
  if ($key !== '_expiration-date' || ! $new_value) {
    return $new_value;
  }

  $new_value = get_gmt_from_date($new_value, 'U');
  return $new_value;
}

Result:

 

Where do I add this code?

Add it in the functions.php in your theme or your child theme folder, or you can use the “code snippets” plugin to load it in wp-admin.