Viewing 2 reply threads
  • Author
    Posts
    • #4464
      Sander Schat
      Member

      Goodday!

      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 fine

      So, for now, i have disabled this feature.

    • #4487
      Steve
      Keymaster

      @sschat– Good to hear from you…it’s been a while. 😉

      Can you post your code for creating your new users column so we can debug?

    • #4513
      Sander Schat
      Member

      Hi 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.

Viewing 2 reply threads
  • The topic ‘custom users column’ is closed to new replies.