3

Is there a way to replace the WP_List_Table object of a post type to display said post type differently on the Admin edit.php page?

3
  • Are you looking to add in extra columns, remove columns, what specifically is it you want to change about the WP_List_Table?
    – user10106
    Commented Jan 16, 2014 at 6:11
  • Not add columns but completely replace it with a custom UI Commented Jan 16, 2014 at 6:12
  • Well there are hooks available that allow you to put content above and below, edit things per row and/or column alongside the fact you can override with custom CSS & JS. Would that be the direction you want to go?
    – user10106
    Commented Jan 16, 2014 at 6:14

2 Answers 2

5

No, you cannot replace the list table. There is no filter, everything is hard-coded.

But you can change the post type registration, set show_ui to FALSE to prevent the built-in page, and add a custom page for the post type listing to show the editable items.

add_action( 'wp_loaded', function(){
    register_post_type(
        'test',
        array(
            'labels' => array(
                'name' => 'TEST'
            ),
            'public' => TRUE,
            'show_ui' => FALSE
        )
    );
});

add_action( 'admin_menu', function(){
    add_object_page(
        'TEST',
        'TEST',
        'edit_test',
        'test',
        function(){
            echo 'test'; // list post type items here
        }
    );
});

Result

screen shot

8

This example is applied to post post type. This is leveraging the WP_Posts_List_Table class and views-edit-{$post_type} filter. This seem isn't the best way, but it works:

Make sure the class is loaded on your page:

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

Extend the WP_Posts_List_Table class to remove list table and define the custom content:

class wpse_CustomTable extends WP_Posts_List_Table
{       
    // remove search box
    public function search_box( $text, $input_id ){ }

    // Your custom list table is here
    public function display() {
        echo "Test";
    }
}

Use it inside a filter hook:

// hook into `views-edit`
add_filter( 'views_edit-post',  "sstssfb_custom_list_table");    
// Override the post table object
function sstssfb_custom_list_table() {
    global $wp_list_table;
    $mylisttable = new wpse_CustomTable();
    $wp_list_table = $mylisttable ;    
}

Result:

enter image description here

2
  • 1
    Note that I adjusted my table class extension example here, by calling the prepare_items() method . This would be needed for the pagination to work as expected. I also modified it with object cloning.
    – birgire
    Commented Oct 13, 2015 at 8:45
  • Thanks man appreciate your answer also works for me.
    – Arman H
    Commented Apr 27, 2022 at 5:24

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.