我已经使用这段代码在 WP 中创建了管理栏:
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_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;
}
}
And it was showing now .我现在的问题是我想显示用户组名称而不是 ID
. It was in the table custom_user_group
.
最佳答案
试试这段代码:
$groups=$pages->group_access;
$groupsArray = explode(',', $groups);
foreach($groupsArray as $singleGroupId){
//use some code to retrieve the group name from 'custom_user_group' with the help for $singleGroupId
}
使用上面的代码并添加使用$singleGroupId
检索名称的方法关于php - WP 从数据库中的表中获取页面管理自定义列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26115491/