Custom column on CPT not showing correct value when meta data not set
Basically I have 2 custom columns in the 'edit.php' of my custom post type. What I need is when $item_type is set to 'page' but there is no page selected, 'No selection' is echoed (same for when 'media' is set but there is no media file selected). What happens is it's showing the title of the post instead of the proper echo. It works fine for when the page or media file variable is set. Just when it's not set. My code is below, thank you in advance to any help offered.
function my_show_columns($name) {
global $post;
$hidden_page = get_the_title(get_post_meta($post-ID, 'hidden_page', true));
$hidden_file = get_the_title(get_post_meta($post-ID, 'media_file', true));
$item_type = get_post_meta($post-ID, 'item_type', true);
switch ($name) {
case 'hidden_item_type':
if (empty(get_post_meta($post-ID, 'item_type', true))) {
echo 'Please select type of item to hide';
} else {
echo $item_type;
}
break;
case 'hidden_item_info':
if(get_post_meta($post-ID, 'item_type', true) == 'page') {
echo 'Title: ' . $hidden_page;
} elseif(get_post_meta($post-ID, 'item_type', true) == 'media') {
echo 'Title: ' . $hidden_file;
} elseif ( empty(get_post_meta($post-ID, 'hidden_page', true)) ) {
echo 'No selection';
} elseif ( empty(get_post_meta($post-ID, 'media_file', true)) ) {
echo 'No selection';
}
break;
}
}
I'm hooking on at:
add_action('manage_posts_custom_column', array($this, 'my_show_columns'));