0

Failing miserably at adding a custom column

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 column only ever shows -- Yes, I have verified $pt[0]->name var_dumps what it actually should be.

So, what am I doing wrong here? I need the Type column to show my pricing_type value.

pricing is a custom post type, while pricing_type is a custom taxonomy of the pricing post type.

1
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;
    }
}
0

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;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.