自定义邮政类型管理器的自定义列

时间:2017-02-16 作者:Kevin

在添加自定义列时失败惨重

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 岗位类型。

2 个回复
最合适的回答,由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;
    }
}

相关推荐

将搜索值添加到wp_list_table分页

我有一个使用wp\\u list\\u table的自定义WordPress表,其中有一个搜索字段:搜索效果很好,但我发现当有多页结果时,搜索值不会添加到分页链接中。以下是我的完整代码:if ( ! class_exists( \'WP_List_Table\' ) ) { require_once( ABSPATH . \'wp-admin/includes/class-wp-list-table.php\' ); } class Customers_List