在添加自定义列时失败惨重
add_action(\'manage_edit-pricing_columns\', \'manage_pricing_columns\');
add_action(\'manage_pricing_posts_custom_column\', \'manage_pricing_custom_columns\');
function manage_pricing_columns($_columns) {
$new_columns[\'cb\'] = \'<input type="checkbox" />\';
$new_columns[\'title\'] = _x(\'Pricing Item\', \'column name\');
$new_columns[\'categories\'] = _x(\'Type\', \'column name\');
$new_columns[\'date\'] = _x(\'Created\', \'column name\');
return $new_columns;
}
function manage_pricing_custom_columns($column, $post_id){
global $post;
switch($_columns) {
case \'categories\':
$pt = get_the_terms( $post_id, \'pricing_type\' );
echo $pt[0]->name;
break;
default:
break;
}
}
Type
仅显示列
--
是的,我已经核实了
$pt[0]->name
var_dumps
它实际上应该是什么。
那么,我做错了什么?我需要Type
列以显示我的pricing_type
价值
pricing
是自定义帖子类型,而pricing_type
是的自定义分类法pricing
岗位类型。
最合适的回答,由SO网友:codiiv 整理而成
add_action(\'manage_edit-pricing_columns\', \'manage_pricing_columns\');
add_action(\'manage_pricing_posts_custom_column\', \'manage_pricing_custom_columns\');
function manage_pricing_columns($_columns) {
$new_columns[\'cb\'] = \'<input type="checkbox" />\';
$new_columns[\'title\'] = _x(\'Pricing Item\', \'wp\');
$new_columns[\'categories\'] = _x(\'Type\', \'wp\');
$new_columns[\'date\'] = _x(\'Created\', \'wp\');
return $new_columns;
}
function manage_pricing_custom_columns($column, $post_id){
global $post;
switch($_columns) {
case \'pricing_type\':
$pt = get_the_terms( $post_id, \'pricing_type\' );
echo $pt[0]->name;
break;
default:
break;
}
}
SO网友:Kevin
Or
add_action(\'manage_edit-pricing_columns\', \'manage_pricing_columns\');
add_action(\'manage_pricing_posts_custom_column\', \'manage_pricing_custom_columns\');
function manage_pricing_columns($_columns) {
$new_columns[\'cb\'] = \'<input type="checkbox" />\';
$new_columns[\'title\'] = _x(\'Pricing Item\', \'column name\');
$new_columns[\'pricing_type\'] = _x(\'Type\', \'column name\');
$new_columns[\'date\'] = _x(\'Created\', \'column name\');
return $new_columns;
}
function manage_pricing_custom_columns($column){
global $post;
switch($column) {
case \'pricing_type\':
$pt = get_the_terms( $post->ID, \'pricing_type\' );
echo $pt[0]->name;
break;
default:
break;
}
}