1

I've added a new page to my admin area, and am now trying to add an admin table to this page, using the WP List Table class (per these instructions). Per the instructions, I would like to first display just an empty table: simply headers, with no rows of data (as in this screenshot). I'm having trouble doing so. I've added the suggested code, but my table still displays only No items found., with no headers (screenshot). Any ideas why this is occurring? My code is below.

There are no errors in the PHP log.

I've also seen these instructions, which are similar (but not identical to) the instructions I'm using. But following them yields the same issue.

Thanks in advance.


Code added to functions.php

    if(!class_exists('WP_List_Table')){
      require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
    }

    class User_List_Table extends WP_List_Table {
        public function get_columns() {     
            $table_columns = array(
                'cb'        => '<input type="checkbox" />', // to display the checkbox.          
                'user_login'    => 'User Login',
                'display_name'  => 'Display Name',
                'ID'        => 'User Id'
          );        
          return $table_columns;           
    }   
    public function prepare_items() {}
  }

Code added to page to display the table.

$wp_list_table = new User_List_Table();
$wp_list_table->display();
0

1 Answer 1

1

I unfortunately don't have an exact answer to my question. But I was able to resolve my issue by starting from scratch, and using this plugin as a guide: Custom List Table Example The plugin contains just one PHP file, which creates a new admin page for you, and adds a full admin table. The PHP file is very heavily commented, and serves as a tutorial for exactly how to use the WP List Table class, and its methods. It explains exactly what each method is, whether it is required or not, and what features it adds. It was very helpful. This was by far the best and most practical of all the WP List Class tutorials I found online.

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.