The correct syntax for using with global keyword. To access a global variable in WordPress, you first need to globalize the variable with global $variable;
Write inside function.php as:
function myfunction(){
global $get_variable;
$get_value = $db->query("SELECT * FROM mytable")->fetch();
$get_variable = $get_value;
}
add_action( 'after_theme_setup', 'myfunction' );
Inside the function you can now able to any where. But, outside of this scope it needs to be re-declared as a global scope variable. Ex., to use inside single.php file, it will work as
global $get_variable;
echo $get_variable;
Related Posts:
- How to: inspect global variables in WordPress
- get_post() vs global $post or $GLOBAL[‘post’]
- How to deal with global information without creating a Singleton class
- Using global $post v/s $GLOBALS[‘post’]
- Accessing $post global on a custom post type archive page
- get_query_var vs global query variables?
- What is the global $wp object used for?
- Change global values from templates
- Will $current_user no longer be global?
- How to avoid repeatedly use the new statement to instantiate a class? [closed]
- Is $page a global variable in wordpress?
- How can i use a global variable in a .css file generated with php?
- Current page id returns the incorrect value
- Echo get_the_category() outside of loop (global?)
- How does WordPress make its functions globally available?
- Recommendations on accessing current user data in WordPress
- WP user agent returns random variables
- How to get particular data from wp_list_comments outside the loop?
- How to save a viewer specific option
- What is the correct way to obtain access to the WP_oEmbed object?
- Creating a (global)-mapping
- wp localize script makes variable global, how to solve that?
- using globals from wp_link_pages function
- How to set and use global variables? Or why not to use them at all
- Should we trust the post globals?
- How to pass arguments from add_settings_field() to the callback function?
- What is a good alternative to using $content_width for image optimization?
- When to use global $post and other global variables?
- Where to get information about array fields in $_REQUEST?
- Global Objects and Public Methods
- What is the difference between using global $current_screen and get_current_screen()?
- Why declare $post globally?
- Create a global variable for use in all templates
- How to set global variable in functions.php
- Passing variables to templates (alternatives to globalizing variables)
- using 1 form shortcode (si or cf7) for all multisite sites [closed]
- Filter the blog title displayed in the header
- Multisite Installation: how do I setup global search?
- Passing variables to template parts
- Should I global $wpdb outside of any of my plugin’s functions scope?
- How should I store global information such as a phone number so that it is editable through the CMS?
- JavaScript, best way to use data from the loop
- WP 4.4.1 allow empty comments via add_action ‘pre_comment_on_post’
- Multisite Global Custom Posts
- Adding a section to admin menu for global settings
- WordPress Multisite – global categories
- Add classname comment template from functions.php
- Cannot update custom database table row
- Defining a global array in functions.php?
- Call global variable array() in woocommerce child/template
- Override global query results without hooks
- WordPress Loop and $post
- How to prevent XSS alter custom global javascript object & methods in WordPress
- Create a new query in function.php to filter blog posts
- Relative redirects for posts, categories, products and product categories
- global variables in templates
- How to access plugin variables from theme templates without using globals?
- Global $post shows null in some of my custom post types archive pages
- Declare Global Variable In OOP PHP
- How can I save custom meta to one global value?
- Does WP have a global of $id?
- What is the use of $content_width?
- Use global variables or function that returns said variables for site-wide private-ish WP settings?
- WordPress Image Slider Looping Title Not Working
- Declare global var from Template File and use it in Functions.php
- how to get the post id in plugin
- get_posts() and global variables
- Passing global variable from header.php to functions.php
- Where is this function’s callback getting its arguments from?
- keep a variable for all pages in memory from the url
- Translation issue with global variables
- How to get submenu of admin menu?
- Detecting current page from class method
- Retrieve post in AJAX Callback
- ‘global’ not working in wordpress?
- Access post ID in “content_save_pre”
- Using global $post; with custom post types
- SFTP define in wp-config.php
- The Global Styles missing
- cannot get global $menu value in form request
- Custom global variable not working in function
- Hide payment method based on user role AND minimum cart value
- Global $wp_admin_bar always returns null
- How do I get a reference to the HTML memory buffer while the page is being constructed?
- global categories – Share specific categories in wordpress multisite
- Declare global variable that can be used on other function
- Popup panel is only displaying 1 entry ignoring all others
- Best way to access variables in template markup
- Settings in functions.php used by a plugin
- How to set global variable in functions.php
- Current URL path variable
- Save something to global var in add_filter
- key( $GLOBALS[‘wp_registered_sidebars’] ) is always showing the same value
- How do I access variables outside a function [closed]
- Global Handle to Class unavailable in Plugin?
- WordPress Multisite and site speed and scaleability
- $do_not_duplicate is not working in genesis theme
- Suppress errors when using global function
- Dequeue classic-themes.min.css
- Using global variables