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
- C++ #include guards
- How do I include a JavaScript file in another JavaScript file?
- is_plugin_active() returning false on active plugin
- Unable to check if plugin is active
- How to include a plugin’s php file to another plugin functions file [duplicate]
- Check if partial file is called from within header.php or footer.php
- Include files in functions.php
- How to prevent wordpress from loading old versions of jquery in wp_head();?
- Pass a variable to get_template_part
- Single Page WordPress Theme – Using page templates
- _wp_page_template to dynamically use template
- Templates & CSS – Proper Programming Practice?
- WordPress “include TEMPLATEPATH” or?
- Which custom query am I in and how can I access its properties & methods?
- Using Includes in Templates in Document Head
- Correct way to use get_template_part() and get_post_format() with custom post types?
- Possible to use pagename inside get_template_part?
- How to localize inline script called with ajax
- Conditional Ajax inclusion
- Can I change a variable in a content part while calling it?
- the_author() not working outside the loop
- get_template_part() based on get_post_type() for a custom post type instead of get_post_format()
- How to query posts to include specific pages of one post type, and all pages of another post type?
- Where is the template for the ‘standard’ format of a post in the theme twentythirteen?
- Using get_template_part to retrieve a template file based on current post type
- get_template_part and template file names
- how could I load a different template part by page
- Problems with loop
- Calling a Function in Functions.php from an external PHP script
- code is skipping a div
- Showing the WordPress standard text area on a Woocommerce Single Product Page?
- Detect if current page is front page within custom query
- Correct and safe way to include php content in my page
- php include not working in custom page
- Custom post type index (maybe using get_template_part)
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- include specific Pages to wp_list_pages with filter
- Does get_template_part() content gets parsed if it’s not executed?
- Get_template_part seems to be ignoring my template
- Is there a way to retrieve the calling template part?
- can’t access some WordPress function from my plugin
- On click some element i want to use some template
- Pull in an “Include” file based on a WordPress Category ID
- Template not loading with get_template_part or locate_template
- Load templates, pass arguments, and render output from functions.php
- Is_Page doesnt detect my page
- Display a custom 404 page without a redirect
- How to get value from radio buttons meta box, and return different contents?
- When to use content-pagename.php?
- post content includes and seo vs. duplicate content
- how to modify request to get_template_part()?
- If I define a variable in header.php, how do I make it available to templates?
- White Screen When Includding A Folder With PHP Files
- wordpress.org disallowing my plugin becuase of loading core files in cron cpanel file
- Javascript file not included only on home page
- Headers already sent error with get_template_part in REST API call
- get_template_part() does not render after the ajax request
- Separate page for pagination possible?
- How to include Elementor CSS in custom php file [closed]