嘿,所以我能想出一些有效的方法。我不知道这是否是最好的方法,但它对我很有效。如果你有更好的想法,请张贴答案。
基本上,我必须改变陈述的顺序。最终的代码如下所示:
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\') && (empty(get_post_meta($post->ID, \'hidden_page\', true))) ) {
echo \'No selection\';
} elseif ( (get_post_meta($post->ID, \'item_type\', true) == \'media\') && (empty(get_post_meta($post->ID, \'media_file\', true))) ) {
echo \'No selection\';
} elseif (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;
}
break;
}
}
我不知道为什么这个方法有效,而另一种方法无效。我猜这是他们被评估的顺序。不管怎样,都在这里。