Skip Navigation

[Closed] Adding Columns to Custom Post List Display

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 11 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

This topic contains 3 replies, has 2 voices.

Last updated by Ghennadi 11 years, 2 months ago.

Assisted by: Ghennadi.

Author
Posts
#37865
CustomPostPage.png

Hi,

I'm writing to see if it's possible to add additional columns to the list display of a custom post created with WP-Types. I've attached a screenshot of the page that I'm talking about.

For example, all of these posts have a field for the Product ID. Is it possible to display the product ID on this page?

Thanks!

#37872

Dear Adams,

You have to add this code to your_theme_path/functions.php with some modifications:

//Add custom column
add_filter('manage_edit- YOURPOSTTYPENAME _columns', 'my_columns_head');
function my_columns_head($defaults) {
$defaults['YOURCOLUMNNAME'] = 'YOURCOLUMNTITLE';
return $defaults;
}
//Add rows data
add_action( 'manage_ YOURPOSTTYPENAME _posts_custom_column' , 'my_custom_column', 10, 2 );
function my_custom_column($column, $post_id ){
switch ( $column ) {
case ' YOURCOLUMNNAME ':
echo get_post_meta( $post_id , 'YOURCUSTOMFIELDNAME' , true );
break;
}
}
Where:
YOURPOSTTYPENAME - name of your post type slug
YOURCOLUMNNAME - name of your column, must be unique and without spaces. e.g. prodict_id
YOURCOLUMNTITLE - column title string.
YOURCUSTOMFIELDNAME - custom field name. e.g. wpcf-product_id

You can learn more at:
http://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

#37875

Hi Gen,

Thanks for the reply.

I'm able to get the column to display, but it's not populating with data.

Is YOURCOLUMNNAME arbitrary?

Here is the code that I'm using:

//Add custom column
add_filter('manage_edit-clearance-sale-item_columns', 'my_columns_head');
function my_columns_head($defaults) {
$defaults['clearance_product_id'] = 'Product ID';
return $defaults;
}
//Add rows data
add_action( 'manage_clearance-sale-item_posts_custom_column' , 'my_custom_column', 10, 2 );
function my_custom_column($column, $post_id ){
switch ( $column ) {
case 'clearance_product_id':
echo get_post_meta( $post_id , 'clearance-item-id-1' , true );
break;
}
}

I've double checked that I'm using the current slugs. Any idea why the data wouldn't be getting to the column?

#37890

Dear Adams,

in line: echo get_post_meta( $post_id , 'clearance-item-id-1' , true );
try to use wpcf-clearance-item-id-1

Also, you can check field names at:
hidden link

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

The topic ‘[Closed] Adding Columns to Custom Post List Display’ is closed to new replies.