2017-08-26 63 views
0

我已将一个新列添加到自定义帖子类型以显示帖子的ID。这适用于WordPress核心帖子类型,但不适用于我的自定义帖子类型。我曾尝试使用manage_ {post_type} _custom_column挂钩,并将其应用于所有帖子,但都无效。自定义列不显示任何内容

它确实添加了自定义列标题,但在查看自定义帖子类型时,我无法用任何东西填充它们。

This is what it looks like when viewing the custom post typethis 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; 
     } 
} 

回答

0

我只是想你的代码,它似乎在这两种情况下是工作完美对我的WordPress:自定义后和。

也许你的错误发生是因为你的帖子是草稿?我不这么认为,但也许。 (我在你的代码中也试过了我的安装中的草稿,它工作正常)。以下是屏幕截图:screenshot

尝试打印“hello world”而不是$ post_id以检查是否在所有情况下都打印。

0

事实证明,该帖子类型被设置为分层。层次帖子类型需要通过与此处使用的不同的操作和过滤器进行定位。