0

It seems that Wordpress does not save the post date in UnixTimeStamp in the database, and it comes up with the whole date and time format, as we can see in the image below. enter image description here

With this introduction in mind, I need to know how I can display the LOCAL date and time in the admin panel, instead of the default Gregorian date. Just as to get clearer about what I mean, just look at the following image.

enter image description here

I am going to display the post date and time in local calendar which is not Gregorian. I never intend to change what is there in the database; I just need to display it in the local calendar in the admin panel. I don't have any problems with the conversion itself. I can easily get the UnixTimeStamp using $stamp = get_post_timestamp($post); and then convert it to local date and time. However, I have no clues how how to show it in the above picture; in other words, how can I put the result of my conversion in the "date column" in the table in the above image. I want this to apply to all of the posts being created with a certain Wordpress plugin. Any help will be welcome. Many thanks in advance.

1

Column filter: The filter for modifying, removing or adding columns to post list in WordPress admin panel is manage_{$post_type}_posts_columns. Exchange {$post_type} with the desired post type. For example; if you want to edit columns for post type 'post', the filter name would be manage_post_posts_columns. And for a custom post type 'product', the filter name would be manage_product_posts_columns.

Column content hook: The hook for controlling the output of the column content in WordPress admin panel is manage_{$post_type}_posts_custom_column with the desired post type. For example; if you want to edit columns for post type 'post', the filter name would be manage_post_posts_custom_column.

For your case you need to remove default date column and add your custom column with your local date. See the example code below for 'post' type.

// manage the columns of the `post` post type
function manage_columns_for_post($columns){
  //remove columns
  unset($columns['date']);
  
  //add new columns
  $columns['local_date'] = 'Local Date';
  
  return $columns; 
}

add_action('manage_post_posts_columns','manage_columns_for_post');

// populate custom columns for `post` post type
function populate_post_custom_columns($column,$post_id){

  //local date column
  if($column == 'local_date'){
    // convert date to local by $post_id
    echo 'Published <br> 2020/12/12 at 6:30 am'; // dynamically get date of each post and display it 
  }
}

add_action('manage_post_posts_custom_column','populate_post_custom_columns',10,2);

Hope it will be usefull.

1
  • Thanks dear, even though I managed to do it applying another approach, your code is logically correct. Thanks again. – H. M.. Dec 17 '20 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.