0

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:

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: http://screencast.com/t/z1uJ3KinklN

My problem right now is I want to display the the User Group Name not the ID It was in the table 'custom_user_group': http://screencast.com/t/StBmVBfD0

Please help.

1 Answer 1

0

Not tested but this should work:

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);
  }
}
3
  • it really WORKS! thanks a lot bro. I really appreciate it. :)
    – Kiko Lolo
    Sep 30, 2014 at 13:20
  • glad that I helped, cheers Sep 30, 2014 at 15:12
  • yes, it really helps, I'm just looking for code to have a filter option on the top for the Group Names like a select option that list the Group Name then when click the Filter button it will display pages having the selected Group Names. And I think thats really hard :(
    – Kiko Lolo
    Oct 2, 2014 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.