我设置了以下代码以在我的帖子列表上显示一列,希望显示我设置的名为“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');
该列的标题应为“Cook Time”。但是该列是空的。当我替换“get_post_meta($post_id, 'cook_time', true);” 用“the_meta();” 该列填充了帖子的所有自定义字段,包括它们的键和值。
我只想要名为“cook_time”的特定字段的值,这是我在 WooCommerce 中的产品发布中的自定义字段。我尝试用“$product_id”和“$product->id”替换“$post_id”,但这些都不起作用。
我究竟做错了什么?