更新时间:2023-11-29 22:54:28
过滤器 manage_edit-{post_type}_columns
仅用于实际添加列.要控制每个帖子(产品)的列中显示的内容,您可以使用 manage_{post_type}_posts_custom_column
操作.为每个帖子的每个自定义列调用此操作,并传递两个参数:$column
和 $postid
.
The filter manage_edit-{post_type}_columns
is only used to actually add the column. To control what is displayed in the column for each post (product), you can use the manage_{post_type}_posts_custom_column
action. This action is called for each custom column for every post, and it passes two arguments: $column
and $postid
.
使用此操作非常简单,您可以在下面找到显示自定义字段offercode"的示例:
Using this action is quite easy, you can find an example to display the custom field "offercode" below:
add_action( 'manage_product_posts_custom_column', 'wpso23858236_product_column_offercode', 10, 2 );
function wpso23858236_product_column_offercode( $column, $postid ) {
if ( $column == 'offercode' ) {
echo get_post_meta( $postid, 'offercode', true );
}
}
您还可以使用插件来控制此行为,例如管理栏.
You could also use a plugin to control this behaviour, such as Admin Columns.