【发布时间】:2017-08-26 23:17:19
【问题描述】:
我在自定义帖子类型中添加了一个新列以显示帖子的 ID。这适用于 WordPress 核心帖子类型,但不适用于我的自定义帖子类型。我尝试使用 manage_{post_type}_custom_column 钩子并将其应用于所有帖子,但都不起作用。
它确实添加了自定义列标题,但在查看自定义帖子类型时我根本无法用任何内容填充它们。
This is what it looks like when viewing the custom post type 和 this is what it looks like when viewing a regular core post.
// Add post ID column to use an order ID in all posts view.
add_filter('manage_posts_columns', 'oms_order_id_header');
add_action('manage_posts_custom_column', 'oms_order_id_column', 10, 2);
function oms_order_id_header($columns) {
//Remove title column
//unset($columns['title']);
//Add new columns
$columns['order_id_header'] = 'Order ID';
$columns['customer_header'] = 'Customer';
$columns['author'] = 'Owner';
return $columns;
}
function oms_order_id_column( $column, $post_id ) {
if ($column == 'order_id_header') {
echo $post_id;
}
}
【问题讨论】:
标签: wordpress custom-wordpress-pages wordpress-hook