我已经使用以下代码在WP中创建了admin列:
add_filter(\'manage_pages_columns\', \'page_custom_cols\', 10);
function page_custom_cols($pages_columns, $post_type) {
$pages_columns[\'user_group\'] = \'User Group\';
return $pages_columns;
}
现在,我添加了获取用户组id的函数,该字段已经在wp\\u post表中,但以逗号分隔的文本显示,如下所示:“1,7,2”,我可以使用此函数显示它:
add_action(\'manage_pages_custom_column\', \'display_page_custom_cols\', 10, 2);
function display_page_custom_cols($col_name, $post_id) {
if (\'user_group\' == $col_name) {
$pages = get_post($post_id);
echo $pages->group_access;
}
}
现在它正在显示:
http://screencast.com/t/z1uJ3KinklN我现在的问题是,我想显示用户组名称,而不是表“custom\\u User\\u Group”中的IDIt:http://screencast.com/t/StBmVBfD0
请帮忙。
最合适的回答,由SO网友:Diogo Gomes 整理而成
未测试,但应能正常工作:
add_action(\'manage_pages_custom_column\', \'display_page_custom_cols\', 10, 2);
function display_page_custom_cols($col_name, $post_id) {
global $wpdb;
$user_group = $wpdb->get_results("SELECT * From custom_user_group",OBJECT_K);
if (\'user_group\' == $col_name) {
$pages = explode(\',\',get_post($post_id));
$output = array();
foreach ($pages as $page ) {
$output[] = $user_group[$page]->GroupName;
}
echo implode(\',\',$output);
}
}