无法显示自定义post类型的列值。根据WordPress文档,我使用正确的过滤器和操作。
为了确保我做得对,我准备了一个简单的插件,它基于官方文档中的示例来启动定制post类型并添加自定义列。
不幸的是,我添加的列仍然没有填充"lorem“。
在分析Wordpress代码时,我注意到在
未执行定义操作wp-admin/includes/class-wp-posts-list-table.php的manage_{$post->post_type}_posts_custom_column。

这是完整的插件代码。
xpost
xpostcol栏:
<?php
/**
* Plugin Name: XPlugin
*/
add_action('init', 'xplugin_register_post_type');
add_filter('manage_xpost_posts_columns', 'xplugin_manage_posts_columns');
add_action('manage_xpost_posts_custom_column', 'xplugin_manage_posts_custom_column', 10, 2 );
register_activation_hook(__FILE__, 'xplugin_register_activation_hook');
function xplugin_register_post_type() {
$labels = array(
'name'=> 'XPosts'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'xpost' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
);
register_post_type( 'xpost', $args );
}
function xplugin_register_activation_hook() {
xplugin_register_post_type();
flush_rewrite_rules();
}
function xplugin_manage_posts_columns($columns) {
unset($columns['author']);
$new_columns = array('xpostcol' => 'XPost Column');
return array_merge($columns, $new_columns);
}
function xplugin_manage_posts_custom_column($column, $post_id) {
switch ($column) {
case 'xpostcol' :
echo 'Lorem ipsum';
break;
}
}发布于 2020-07-06 17:58:57
当我从正式的Docker映像运行WordPress容器时,插件工作不正确。在运行基于Apache + PHP + MySQL和手动WordPress安装的自定义容器的情况下,插件可以正常工作。
https://stackoverflow.com/questions/62626159
复制相似问题