下面的代码将在用户表(users.php)上创建一列,并显示分类术语的名称。如果您有具有指定自定义角色的用户,则此选项适用于您。数据库将只显示对象中的id,但此代码将从id中提取名称并将其显示在users表中:
<?php
// Display column on user table
add_filter(\'manage_users_columns\', \'column_register_acf_name\');
add_filter(\'manage_users_custom_column\', \'column_display_acf_name\', 10, 3);
function column_register_acf_name($columns)
{
$columns[\'id_col\'] = \'ID Name\';
return $columns;
}
//Adds Content To The Custom Added Column
function get_names($term_id)
{
global $wpdb;
$result = $wpdb->get_var($wpdb->prepare("SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id));
return $result;
}
function column_display_acf_name($value, $column_name, $user_id)
{
$user_info = get_user_meta($user_id, \'gatekeeper\', true);
$ints = array_map(\'intval\', $user_info);
$names = array_map(\'get_names\', $ints);
if ($column_name == \'id_col\') return implode(\', \', $names);
return implode($value);
}