I have a custom WP table that I query to get back an array of values. What I need is to make these variables exist throughout the entire WP site.

I’m not sure what the best way to do that is.
Here’s my function:

function get_dealer_info(){
  global $wpdb;
  $table_name = $wpdb->prefix . "dealer_info";
  $dealerInfo = $wpdb->get_results( "SELECT * FROM $table_name" );

  return $dealerInfo;
global $dealerInfo;
add_action('init', 'get_dealer_info');

So I’d like to use this like

echo $dealerInfo['field1']; 

Or something of the sort. Does that make sense?

Read more here: How can I make an object available through the entire site?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: