php - WP 从数据库中的表中获取页面管理自定义列

标签 php mysql sql wordpress admin

我已经使用这段代码在 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/

相关文章:

PHP/MySQL : Simple timekeeping and update scheme?

php - 警告 : Missing 1 argument

javascript - 如何使用 javascript 从日期转换为 unix_timestamp

mysql - 在 MySQL 中复制行

mysql - 将旧版 MySQL 脚本转换为 Postgres 9.5

php - symfony2实体的slugify方法在哪里

php - 安装 CMS Concrete5 版本 5.7.2.1 时出现疯狂长 "exception occurred"

php - 当客户端按下按钮时 PHP 中的计数器

mysql - 如何搜索表 1 中的某些数据和表 3 中的其他数据的位置,并且两者的 UUID 相同

sql - Access 中的简单 SQL 查询因缺少分号错误而失败