Add a download csv button in a custom admin page


I have build a custom WordPress admin page. In it i’m extending the wp-list-table class like demonstrate here

I have a form that sets some arguments to filter the results that will be showed in the list.

It works great.

But I want to add a button to download the filtered data.

like to see here :
enter image description here

The button is outputed in the extra_tablenav function.

public function extra_tablenav($which) {
        if ( $which == "top" ){

            $data = $this->generate_WP_Query();

            if( isset( $data ) ) {
                submit_button( 'Download the csv', 'primary', 'download_stock_csv' );

                global $plugin_page;

                if ( $plugin_page == 'dw-custom-stock-export' && isset( $_POST['download_stock_csv'] ) ) {

         if ( $which == "bottom" ){
            //The code that goes after the table is there

But I always get a empty query.

Anybody got an idea how to do this?

, DistrictWeb 4 years 2019-06-05T10:13:46-05:00 0 Answers 93 views 0

Leave an answer