Skip to content

Instantly share code, notes, and snippets.

@ka215
Last active June 8, 2016 02:09
Show Gist options
  • Save ka215/04fa30ca5d1fa16dc64eb4876a660ce9 to your computer and use it in GitHub Desktop.
Save ka215/04fa30ca5d1fa16dc64eb4876a660ce9 to your computer and use it in GitHub Desktop.
For Custom DataBase Tables plugin; this filter hook code is sample to modify the display format of any datetime column of the specified table. About the allowed the alias of datetime format, please refer: https://ka2.org/cdbt/v2/basic-info/plugin-options/general-setting/#datetime-formats
<?php
// You should be optimize the variables of "$target_table" and "$target_column" in proportion to your table structure.
function cdbt_custom_datetime_format( $columns, $shortcode_name, $table ) {
$target_table = 'your_table_name';
$target_column = 'datetime_column_name';
if ( $target_table === $table ) {
foreach ( $columns as $_i => $_column ) {
if ( $target_column === $_column['property'] ) {
$_custom_column = sprintf( 'convert_datetime(rowData["%s"], ["%s"])', $target_column, 'F j, Y' );
$columns[$_i]['customColumnRenderer'] = $_custom_column;
}
}
}
return $columns;
}
add_filter( 'cdbt_shortcode_custom_columns', 'cdbt_custom_datetime_format', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment