Skip to content

Instantly share code, notes, and snippets.

@MjHead
Created December 21, 2018 09:43
Show Gist options
  • Save MjHead/ccf94293dc89e50e6ced143f4ece315a to your computer and use it in GitHub Desktop.
Save MjHead/ccf94293dc89e50e6ced143f4ece315a to your computer and use it in GitHub Desktop.
Custom callback function example
<?php
/**
* Custom callback example
*
* @param string $column Column name
* @param int $post_id Post ID
* @return string
*/
function jet_admin_column_callback_example( $column, $post_id ) {
return 'Example output: ' . get_the_title( $post_id );
}
@Brink67
Copy link

Brink67 commented Aug 4, 2019

If trying to use this to format a date for a timestamp custom field to be included in a custom post type admin panel view, How do I retrieve the contents of the custom field? event_date is the Name / ID of the custom metafield in the custom post type. The idea is that $rawdate will collect and hold the int value of the event_date meta field, and $cleardate will run the date() function and hold a string - plain english date - based on the value held in $rawdate.

I'm trying this

`

function returncleardate( $column, $post_id ) {
$rawdate = $event_date;
$cleardate = date('l jS \of F Y',$rawdate);
return $cleardate;}
`
And get nothing returned.

I know that I'm getting NULL for $rawdate due to this temporary code

function returncleardate( $column, $post_id ) { $rawdate = $event_date; return var_dump($rawdate);}
When $rawdate = get_the_title( $event_date );
Then I get the title.

When $rawdate = get_the_date( $event_date );
I get the creation date of the post.

get_the_title and get_the_date are obviously functions that are already defined somewhere.
what is the function for get the field or get the term?

I think I'm on the right track. Just need a little guidance.

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