This is essentially scope visibility issue. include
brings code into a current scope, function call creates new closed off scope. In get_template_part()
only certain WordPress globals are being made available by load_template()
call inside.
While the basic answer is to declare your variables as globals, you might want to ponder your overall architecture a bit — this is typically not a good sign in code.
Related Posts:
- Serving precompressed content with Brotli on Apache
- Passing variables through locate_template
- Is there any way to use get_template_part() with folders?
- Should we use get_template_part() in functions files instead of include_once?
- How can I avoid code duplication for a blog with lots of source code?
- passing argument to get_template_part() or a better way to code
- How to rename wp-includes folder?
- What’s the correct way to include files in WordPress TwentyTen theme with it’s own jquery scripts and css?
- Passing variables to template parts
- ABSPATH not working! Any idea why?
- Get current user data from external PHP page
- External system integration with wordpress
- Why does get_template_part() break variables?
- Problems Including File
- How to include core files into plugin
- How to check if txt file exists inside template folder?
- What’s the best way to ‘include’ a file in WordPress?
- locate_template function – File not getting included
- Can not include file from plugin into theme
- Include tags from array, ignore the rest in get_the_tags
- PHP files included within functions.php don’t work from admin area
- Wp Enviroment problem with included file
- Having trouble linking to file using relative path
- How can I include an external file in a post or page?
- Including php file in directory above WordPress installation
- add_feed failed to open stream
- Load content From Include File within plugin
- including Zend Gdata library path error
- Adding a second loop breaks everything
- What about “inc” (include) files and Child Theming? Is it possible?
- get_template_part for template in subdirectory not working
- Make changes in /includes/http.php update safe
- Need to override file included in parent theme
- Class works in Admin, not found on Front End
- Using require_once for parent-directory not working but is working in sub-directories
- if statement parent page for child pages
- Theme parts path location dump
- add_action outside a plugin
- Add page as static html into another page
- Dynamically determine URI to scripts and styles included with a class which could be added from plugin/theme/child theme/mu plugin
- strange parse error when including a loop template within another template
- Include another HTML file in a HTML file
- C++ #include guards
- C++ #include guards
- Inserting a PDF file in LaTeX
- How do I run a file on localhost?
- class not declared in scope – even though .h was included
- Already defined in .obj – no double inclusions
- How do you #include files in java?
- How do I include a JavaScript file in another JavaScript file?
- Random not declared in scope
- “Multiple definition”, “first defined here” errors
- Error “Unterminated conditional directive” in cross-referencing headers
- “Fatal error: Cannot redeclare function”
- What is the difference between a .cpp file and a .h file?
- Difference between require, include, require_once and include_once?
- How to include file in a bash shell script
- cmath vs math.h (And similar c-prefixed vs .h extension headers)
- How to add a default include path for GCC in Linux?
- Compiler error C4430: missing type specifier – int assumed [duplicate]
- Eclipse CDT: Symbol ‘cout’ could not be resolved
- how to get wp-content folder in wordpress?
- Passing a variable to get_template_part
- get_template_directory_uri pointing to parent theme not child theme
- How to use get_template_part()?
- How to include a file using get_template_part() in a plugin?
- get_template_part vs action hooks in themes
- The proper way to include/require PHP files in WordPress
- Using a custom WP_Query with get_template_part loop
- Is it possible to override the result of get_template_part()?
- How do I replace a function, declared inside a plugin’s class, in functions.php?
- is_plugin_active() returning false on active plugin
- Unable to check if plugin is active
- Is there a variable for a template parts name?
- How to make get_template_part always check child theme first?
- How to include a plugin’s php file to another plugin functions file [duplicate]
- Include WP_Query in my own PHP file?
- Order by & include array by specific post ids
- Include a external PHP file into a WordPress Custom Template
- Include PHP file in Content using [shortcode]
- When is get_template_part() preferable to simply using the template.php files?
- Check if partial file is called from within header.php or footer.php
- How to add custom content template part for a custom post type on main query using a plugin
- get_template_part from plugin
- Combining shortcode and get_template_part
- Include files in functions.php
- What is the right way to include a wp-admin file in your theme?
- How to prevent wordpress from loading old versions of jquery in wp_head();?
- Too many get_template_parts?
- Variable use in get_template_part
- get_template_part() does not work if you call it when you are in a subfolder
- Is it safe/recommended to use wp_enqueue_script function outside the functions.php file?
- Problem requiring/including plugin files with plugin_dir_path( __FILE__ )
- Get the php template file from other theme folder
- load/require specific php files for specific pages/templates/post types
- Loading page content into a variable in template
- How can I include JavaScript that use jQuery on admin side
- Pass a variable to get_template_part
- Why does including a file in theme’s functions.php not work?
- bloginfo(‘stylesheet_directory’) vs. get_stylesheet_directory_uri() and include(‘file.php’) vs. get_template_part()