Skip Navigation

[Resolved] Show custom date field in custom post list display

This thread is resolved. Here is a description of the problem and solution.

Problem:

I added a column to show the custom field "data-inizio" (start date).

For instance the date "9 june 2018, 6pm" becomes "1528567200" in the backend list view...

How can I show the date in an understandable way? Is it also possible to choose its format?

Solution:

It needs to modify the PHP codes, see example here:

https://toolset.com/forums/topic/show-custom-date-field-in-custom-post-list-display/#post-907310

Relevant Documentation:

This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.67 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by nicolaT-2 6 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#906969

Hi,
in the list view of my custom post type "eventi" (events) I added a column to show the custom field "data-inizio" (start date).
To do it I used the code found in this post: https://toolset.com/forums/topic/adding-columns-to-custom-post-list-display/.
The colum is showing but not in the expected format, for instance the date "9 june 2018, 6pm" becomes "1528567200" in the backend list view... How can I show the date in an understandable way? Is it also possible to choose its format? I'd like to see just "9 june 2018" without the hour).

Here is the code i added in my functions.php:
//Add custom column in archivio eventi nel backend
add_filter('manage_edit-evento_columns', 'my_columns_head');
function my_columns_head($defaults) {
$defaults['colonna-data-evento'] = 'Data inizio';
return $defaults;
}
//Add rows data
add_action( 'manage_evento_posts_custom_column' , 'my_custom_column', 10, 2 );
function my_custom_column($column, $post_id ){
switch ( $column ) {
case 'colonna-data-evento':
echo get_post_meta( $post_id , 'wpcf-data-inizio' , true );
break;
}
}

Thanks for your tips!
Nicola

#907310

Hello,

Please try to modify this line from:

echo get_post_meta( $post_id , 'wpcf-data-inizio' , true );

To:

$data_inizio = get_post_meta( $post_id , 'wpcf-data-inizio' , true );
echo date_i18n( get_option( 'date_format' ), $data_inizio ); 

More help:
https://codex.wordpress.org/Function_Reference/date_i18n
Retrieve the date in localized format, based on timestamp.

#907314

Thanks a lot Luo! It's perfect!

Nicola