I've got a bit of a tough question involving a
website and its
web app counterpart.
The website relies on two different databases: its default, named
wp_website, and its counterpart's (aka the
web app), named
Again, the website is powered by
The web app is powered by
I've successfully been able to connect the two databases together. I am able to query the
wp_webapp database from my
I've created a custom
franchise. The template I'm using for each
franchise post is contained within a directory named after its parental
The file directory looks like this:
my-theme |-- content-single-franchise.php |-- single-franchise.php |-- single-franchise |--- history.php |--- location.php |--- name.php |--- photo.php
Rather than import all of the
wp_webapp data into
wp_website, I've decided to generate the
franchise posts on-the-fly using
get_query_var and the
wp_webapp.franchise_id integer value.
The URL to view any franchise looks like this:
In my non-publicly-accessible
franchise-queries.php file is where my external connection settings and all external queries are written. I've stored them all to my
The instance of the
FranchiseDatabase class is stored to the
$franchiseRecords variable also contained within the
franchise-queries.php file. I then define
wp-config.php so that it is globally accessible.
The File Contents
single-franchise.php file, I've declared
$franchise_id = get_query_var( 'franchise_id', false );
Within that same file, I call
get_template_part( 'content', 'single-franchise' );
The overall template is generated using custom
global $franchise_id, $franchiseRecords; // My first call to `$franchiseRecords` // `var_dump( $franchiseStats )` confirms data from wp_webapp is being pulled $franchiseStats = $franchiseRecords->get_franchise_stats( $franchise_id ); do_action( 'fran_location_name' ); // Loads single-franchise/name.php do_action( 'fran_before_image' ); // Opening <div class="photo"> element do_action( 'fran_single_image' ); // Loads single-franchise/photo.php do_action( 'fran_after_image' ); // Closing </div> for div.photo do_action( 'fran_location_map' ); // Loads single-franchise/location.php do_action( 'fran_location_history' ); // Loads single-franchise/history.php
Beginning in the
photo.php file, I declare
global $franchiseStats. However, when running
var_dump( $franchiseStats ) it returns
NULL and/or empty.
My question is why is it returning
NULL when I've just defined it within content-single-franchise.php?
I know I could just run
$franchiseStats = $franchiseRecords->get_franchise_stats( $franchise_id ); but wouldn't that be redundant?
Any advice would be much appreciated. Cheers!