Tagged: custom column, users
- This topic has 2 replies, 2 voices, and was last updated 6 years, 4 months ago by
Sander Schat.
-
AuthorPosts
-
-
October 8, 2015 at 5:13 am #4464
Sander SchatMemberGoodday!
i have found a ‘feature’…
When adding a new custom column for the ‘users’ table, i couldnt get this column to show any results.
After some research i found the cause:
In the helpers-plugin there is the option : ‘Show ID’s on edit screens for Posts, Pages, Users, etc.’When enabled: my custom column exists, but empty.
When disabled: the new custom column is working fineSo, for now, i have disabled this feature.
-
October 8, 2015 at 10:35 pm #4487
-
October 10, 2015 at 6:11 am #4513
Sander SchatMemberHi Steve, yes all projects are just running without any problems, so no news for a long time
Here some code for the user-column:
// add extra column to users // add_filter( 'manage_users_columns', 'usersColumn' ); function usersColumn( $columns ) { $new = array(); foreach ( $columns as $key => $title ) { if ( $key == 'posts' ) // Put the column before this column { $new['quiz_count'] = 'Aantal lessen'; } $new[ $key ] = $title; } unset( $new["posts"] ); return $new; } // add value to the extra vraag post_type column // add_filter( 'manage_users_custom_column', 'manage_users_custom_fields', 10, 3 ); function manage_users_custom_fields( $val, $column_name, $user_id ) { //$user = get_userdata( $user_id ); switch ( $column_name ) { case 'quiz_count' : $args = array( 'posts_per_page' => - 1, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'dquiz', 'post_mime_type' => '', 'post_parent' => '', 'author' => $user_id, 'post_status' => 'publish', 'suppress_filters' => TRUE ); $posts_array = get_posts( $args ); return count( $posts_array ); break; default: } return $val; } // Make it sortable // add_filter( 'manage_users_sortable_columns', 'users_sortable_column' ); function users_sortable_column( $columns ) { $columns['quiz_count'] = 'quiz_count'; return $columns; }It creates the column, and makes it sortable.
I didnt post the actual ‘ordering’ query. But no need for this here.
It just didnt show any value, when the “show IDS” was enabled in the helpers-plugin.
-
-
AuthorPosts
- The topic ‘custom users column’ is closed to new replies.