Why is there a bunch of WordPress HTML code in my browser CSV download?

This code cannot run in a shortcode: if ( $_SERVER[‘REQUEST_METHOD’] == ‘GET’ && isset($_GET[‘CSV’]) ) { require_once __DIR__ . ‘/../assets/helpers.php’; // contains csv_download() function csv_download(); } The problem is that by the time a shortcode executes it’s too late to send HTTP headers, and WordPress has already sent the theme header and HTML body tags. … Read more

How to export tag counts to excel?

Please note that this stack is more focused on development, asking for ready–made solutions like plugins isn’t considered in scope. From perspective of native functionality and power user perspective you can sort tags by count in WP admin interface. You can also tweak how many tags are displayed via Screen Options (top right of page). … Read more

Reading CSV values and showing them in PHP

Not too hard really… $csvdata = file_get_contents($filepath); $lines = explode(“\n”, $csvdata); // split data by new lines foreach ($lines as $i => $line) { $values = explode(‘,’, $line); // split lines by commas // set values removing them as we ago $linevalues[$i][‘name’] = trim($values[0]); unset($values[0]); $linevalues[$i][‘country’] = trim($values[1]); unset($values[1]); $linevalues[$i][‘color’] = trim($values[2]); unset($values[2]); // assign … Read more