Forums

How to use WP_Terms_List_Table in plugin (7 posts)

  1. bkrettly
    Member
    Posted 1 year ago #

    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.

  2. bkrettly
    Member
    Posted 1 year ago #

    /up

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

    Thanks in advance

  3. Mark / t31os
    Moderator
    Posted 1 year ago #

    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.

    http://core.trac.wordpress.org/ticket/15386

  4. Skretch
    Member
    Posted 1 year ago #

    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.

  5. Skretch
    Member
    Posted 1 year ago #

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

  6. bkrettly
    Member
    Posted 1 year ago #

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

  7. demon_firefox
    Member
    Posted 6 months ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic