Viewing 4 reply threads
  • Author
    Posts
    • #2400
      norboo
      Member

      Hi!
      I created a user taxonomy but I’m having problems showing it in the Admin Column (All users)

      | Username | Name | Role | User Type??? |

      This is the code I have in the functions.

      
      // Piklist Custom Taxonomies
      add_filter('piklist_taxonomies', 'piklist_custom_taxonomies');
        function piklist_custom_taxonomies($taxonomies)
        {    
          $taxonomies[] = array(
      		'object_type' => 'user'
      		,'name' => 'user_type'
      		,'show_admin_column' => true
      		,'configuration' => array(
      			'hierarchical' => true
      			,'labels' => piklist('taxonomy_labels', 'User Type')
      			,'show_ui' => true
      			,'query_var' => true
      			
      		)
          );
        
          return $taxonomies;
        }
      

      Another problem is when I delete an user the Users count for the taxonomy term is not updated.

    • #2426
      norboo
      Member

      Anyone?

    • #2429
      Steve
      Keymaster

      @norboo– Sorry for the late reply. Pikilst doesn’t support this yet, but since Piklist does everything the WordPress way, you can easily add this using standard WordPress actions. Place code in your main plugin file, or your themes functions.php. It should look like this when viewing the User List.

      add_filter('manage_users_columns', 'user_column_header', 10, 2);
      add_action('manage_users_custom_column', 'user_column_data', 10, 3);
      
      function user_column_header($columns)
      {
        $columns['user_type'] = __('User Type');
      
        return $columns;
      }
      
      function user_column_data($term_list, $column, $value)
      {
        switch ($column)
        {
          case 'user_type':
            
            $term = wp_get_object_terms($value, 'user_type');
      
            if(isset($term[0]))
            {
              $prefix = '';
      
              foreach ($term as $name => $value)
              {
                $term_list .= $prefix . $value->name;
                $prefix = ', ';
              }
            }
            else
            {
              $term_list = '';
            }
      
          break;
      
          default:
      
            $term_list = '';
      
          break;
        }
        
        return $term_list;
      }
      
    • #2435
      norboo
      Member

      Thanks Steve!
      Works like a charm!

    • #2436
      Steve
      Keymaster

      @norboo– Awesome! show_admin_column for user taxonomies will be supported in the next version of Piklist. Closing this ticket.

Viewing 4 reply threads
  • The topic ‘User Taxonomy in Admin column’ is closed to new replies.