Skip to content

Instantly share code, notes, and snippets.

@MjHead
Created March 20, 2019 09:26
Show Gist options
  • Save MjHead/1025f912a981b2fd73acb2a4c1a13d59 to your computer and use it in GitHub Desktop.
Save MjHead/1025f912a981b2fd73acb2a4c1a13d59 to your computer and use it in GitHub Desktop.
Admin column callback example
/**
* Show formated date from post meta in admin columns
*
* $meta_key - custom field to get date from
* $format - date format
*/
function jet_admin_column_date( $column, $post_id ) {
$meta_key = '_date';
$format = 'F, j Y';
$date = get_post_meta( $post_id, $meta_key, true );
if ( ! $date ) {
return '--';
} else {
return date_i18n( $format, $date );
}
}
@jennlee20
Copy link

jennlee20 commented Oct 10, 2020

Hi, please may i know how to get the meta key in Callback column just like jet_engine_custom_cb_related_posts?
Example i would like to achieve like this
set custom callback as >>> my_custom_admin_callback::my_meta_key
Then i create function

function my_custom_admin_callback( $column, $post_id, $meta_key ) {
/*So i can directly use the meta_key*/
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment