I have a function.php file in my plugin I am making and I want a function that gets all data from a table in the DB then stores it in a $data array. My problem is when I call the function outside the functions file the array is null, if I dump the data array out inside the function and then call the function the data is present so I know the query is successful. Here is my code:
functions.php
    function getCategories() {
    $data = array();
    global $wpdb;
    $data = $wpdb->get_results("SELECT * FROM `metal_work_categories` WHERE 1", ARRAY_N);
    }
index.php
include('functions.php');
getCategories();
var_dump($data);
I also tried initializing the data array in the index.php file and passing it to the function, just a wild stab in the dark really, to no avail:
$data = array();
getCategories($data);
var_dump($data);
 
     
    