0

I have the following code set up to display a column on my post list, wanting to display the values from a custom field I have set up called "cook_time".

function cust_field_text($column_name){
        if($column_name === 'cust_col'){
                 get_post_meta( $post_id, 'cook_time', true );
          }
}
add_action('manage_posts_custom_column', 'cust_field_text', 10, 2);
function cust_fields($column){
    $column['cust_col'] = __('Cook Time');
    return $column;
}

add_filter('manage_posts_columns', 'cust_fields');

The column is appearing with the title "Cook Time," as it should. But the column is empty. When I replace "get_post_meta( $post_id, 'cook_time', true );" with "the_meta();" the column fills with all of the custom fields of the post, including their key and value.

I just want the value of the specific field called "cook_time," which is a custom field in my product postings in WooCommerce. I have tried replacing "$post_id" with "$product_id" and "$product->id", neither of those work either.

What am I doing wrong?

aleks1217
  • 87
  • 13
  • I think problem is in `$post_id`... There is no define `$post_id` in your filter function... – Akshay Paghdar Feb 12 '14 at 06:42
  • Thanks! Yes, I was missing some code. I went at it another way and got this to work beautifully. I kept feeling like part of the problem might be that I was trying to work with "product" and not "post", so I found another code snippet to customize. function custom_column( $column, $product_id ){ global $product; switch( $column ) { case 'cook_time' : $time = get_post_meta( $product->id, 'cook_time', true ); echo __( $time ); if ( empty( $time ) ) echo __( '0' ); default : break; } } – aleks1217 Feb 12 '14 at 15:53

0 Answers0