You don’t need a global $post
object, WP gives the column callback the post ID, which is all that is needed.
Looking at this question/answer, we see this code:
add_filter( 'manage_book_posts_columns', 'set_custom_edit_book_columns' );
function set_custom_edit_book_columns($columns) {
....
$columns['publisher'] = __( 'Publisher', 'your_text_domain' );
return $columns;
}
add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 );
function custom_book_column( $column, $post_id ) {
switch ( $column ) {
....
case 'publisher' :
echo get_post_meta( $post_id , 'publisher' , true );
break;
}
}
Notice that $post_id
was then used to retrieve post meta, and if you needed a post object, $current_post = get_post( $post_id )
can be used.
Generally you don’t need to rely on global variables, particularly $post
, almost all APIs take a post ID, and every field on the post variable is available as a filterable API function. e.g. get_the_title()
etc