WP get page admin custom column from table in database

I already created admin column in WP using this code:

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;
}

Now I added the function to get the user group id, this field is already in wp_post table but in a comma separated text just like this: ” 1,7,2 ” and I was able to display it using this function:

Read More
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. My problem right now is I want to display the User Group Name not the ID. It was in the table custom_user_group.

Related posts

Leave a Reply

1 comment

  1. Try this code:

    $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
        }
    

    Use the above code and add your approach to retrieve the name using $singleGroupId