【问题标题】:Wordpress Custom ColumnsWordPress 自定义列
【发布时间】:2012-02-01 19:38:01
【问题描述】:

我创建了一个名为 Members 的自定义帖子类型。

然后我想自定义此自定义帖子类型的显示以显示已在列中输入的一些自定义元数据。

列正在显示,但数据未显示,我不知道为什么。

add_filter( 'manage_edit-members_columns', 'my_columns_filter', 10, 1 );

function my_columns_filter( $columns ) {
$column_phone = array( 'phone' => 'Phone Number' );
$column_email = array( 'email' => 'Email Address' );
$column_membertype = array( 'member_type' => 'Member Type' );
$columns = array_slice( $columns, 0, 2, true ) + $column_phone + array_slice( $columns, 2, NULL, true );
$columns = array_slice( $columns, 0, 3, true ) + $column_email + array_slice( $columns, 3, NULL, true );
$columns = array_slice( $columns, 0, 4, true ) + $column_membertype + array_slice( $columns, 4, NULL, true );
return $columns;
}

add_action( 'manage_members_custom_column', 'my_column_action', 10, 2 );

function my_column_action( $column, $post_id ) {
global $post;
switch ( $column ) {
    case 'phone':
        echo get_post_meta($post_id, '_cricketss_phone', TRUE);
        break;
    case 'email':
        echo get_post_meta($post_id, '_cricketss_email', TRUE);
        break;
    case 'member_type':
        echo get_post_meta($post_id, '_cricketss_phone', TRUE);
        break;
}
}

任何提示将不胜感激。

【问题讨论】:

  • 粘贴您的register_post_type 代码

标签: wordpress custom-post-type customcolumn


【解决方案1】:

我会在没有register_post_type 代码的情况下试一试。以下是要尝试的事情

  1. 如果您还没有,请将 'hierarchical' => false 添加到您的 register_post_type

  2. 改变

    add_action( 'manage_members_custom_column', 'my_column_action', 10, 2 );
    

    add_action( 'manage_posts_custom_column', 'my_column_action', 10, 2 );
    

我有一种强烈的感觉,你的问题在于我提到的第 2 点。

Codex 声明:

结合 manage_edit-${post_type}_columns 过滤器,这允许您将自定义列添加到列表帖子/页面/自定义帖子类型页面。此处描述的过滤器适用于内置帖子类型以及自定义帖子类型。请注意,如果自定义帖子类型具有 'hierarchical' => true,则要使用的正确操作挂钩是 manage_pages_custom_column。

【讨论】:

    猜你喜欢
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多