Your description of the problem is not very clear, and your inconsistent code formatting makes that hard to read (plus I am pretty sure some code is missing), but if the problem is running the query multiple times you can solve that with a static variable.
function get_gametitle_info() {
static $game_info_query = false;
if (false !== $game_info_query) {
return $game_info_query;
}
/*
the rest of your code
*/
}
You are sort-of “caching” the result, good for the single page load which should help. You can “cache” over multiple page loads using the Transient API.
function get_gametitle_info() {
$game_info_query = get_transient( 'game_info_query' );
if ( !empty( $game_info_query ) ){
return $game_info_query;
}
/*
(most of) the rest of your code
*/
set_transient('game_info_query', $game_info_query, HOUR_IN_SECONDS );
return $game_info_query;
}
That should save the data to the database for an hour before updating it. Obviously you can choose some other time frame. The single simple query should be quicker than the complicated query.
You could even combine the two approaches, though I haven’t tested and I am not sure of the effectiveness of doing so.
function get_gametitle_info() {
static $game_info_query = false;
if (false !== $game_info_query) {
return $game_info_query;
}
$game_info_query = get_transient( 'game_info_query' );
if ( !empty( $game_info_query ) ){
return $game_info_query;
}
/*
(most of) the rest of your code
*/
$game_info_query = 'howdy';
set_transient('game_info_query', $game_info_query, HOUR_IN_SECONDS );
return $game_info_query;
}