Skip to main content
Added an example
Source Link

If you use admin_init no text should be output in the file unless you have some php notice.

Edit:

The following code should do.

<?php
/**
 * download_custom_taxonomy_csv_154304
 */
add_action('admin_init', 'download_custom_taxonomy_csv_154304');
function download_custom_taxonomy_csv_154304 () {
    
    // Check for GET request
    if ( isset( $_GET['download_ct_csv'] ) ){
        header('Content-type: text/csv');
        header('Content-disposition: attachment;filename=myct.csv');

        // Run here your code

        exit;
    }
    
}

If you use admin_init no text should be output in the file unless you have some php notice.

If you use admin_init no text should be output in the file unless you have some php notice.

Edit:

The following code should do.

<?php
/**
 * download_custom_taxonomy_csv_154304
 */
add_action('admin_init', 'download_custom_taxonomy_csv_154304');
function download_custom_taxonomy_csv_154304 () {
    
    // Check for GET request
    if ( isset( $_GET['download_ct_csv'] ) ){
        header('Content-type: text/csv');
        header('Content-disposition: attachment;filename=myct.csv');

        // Run here your code

        exit;
    }
    
}
Source Link

If you use admin_init no text should be output in the file unless you have some php notice.