• Hello,

    I need to use the WP_Terms_List_Table class in my plugin in order to list the categories in a “WordPress like” table (I can remade the table, but it’s not efficient).

    I tried this code :

    $_POST['taxonomy'] = 'category';
    $tax = get_taxonomy( 'category' );
    
    if ( !current_user_can( $tax->cap->manage_terms ) )
        wp_die( __( 'Cheatin’ uh?' ) );
    
    $wp_list_table = _get_list_table('WP_Terms_List_Table');
    $pagenum = $wp_list_table->get_pagenum();
    $title = $tax->labels->name;
    add_screen_option( 'per_page', array('label' => $title, 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page') );
    
    $wp_list_table->prepare_items();
    
    $wp_list_table->display();

    The table exists, but still empty. In fact, not really empty, the tbody looks like this :

    <tbody class="list:tag" id="the-list">
            <tr class="alternate" id="tag-7">
              <td></td>
            </tr>
            <tr id="tag-6">
              <td></td>
            </tr>
            <tr class="alternate" id="tag-5">
              <td></td>
            </tr>
            <tr id="tag-4">
              <td></td>
            </tr>
            <tr class="alternate" id="tag-9">
              <td></td>
            </tr>
            <tr id="tag-3">
              <td></td>
            </tr>
            <tr class="alternate" id="tag-1">
              <td></td>
            </tr>
          </tbody>

    The categories lines exist, but without any informations (name, slug,…).

    What should I do in order to obtain a correct table ?

    Thanks in advance, sorry if my english is weird, I’m French.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter bkrettly

    (@bkrettly)

    /up

    Please, I still didn’t find any way to use this class,

    Thanks in advance

    There’s an example of using the WP_List_Table class inside a plugin in this ticket here, see the two patches attached by Scribu.

    https://core.trac.www.ads-software.com/ticket/15386

    The example is invalid.
    If you look at lines 19-45 of wp-admin/includes/list-table.php you will see that in _get_list_table function there is no way add a custom $core_classes. If a $core_classes doesn’t exist then the function returns false instead of a new class.

    The way to solve the problem is to overwrite get_column_info in you custom WP_List_Table class.

    Thread Starter bkrettly

    (@bkrettly)

    Thanks ! I don’t work on this module at this time, but I’ll try this as soon as possible.

    I finally found a solution:

    if(!class_exists('WP_Terms_List_Table')){
      require_once( ABSPATH . 'wp-admin/includes/class-wp-terms-list-table.php' );
    }
    
    <strong>set_current_screen( 'edit-<em>your_taxonomy</em>' );</strong>
    $terms = new WP_Terms_List_Table();
    $terms->display();

    The most important thing is to set the proper screen.

    You also need to add &taxonomy=your_taxonomy to the page adress.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to use WP_Terms_List_Table in plugin’ is closed to new replies.