Does get_template_part pull data once in a loop?

get_template_part() calls locate_template(), and both functions are running file_exists() checks for the same file over and over. There is no caching. Meh. But … PHP has an internal cache for file look-ups, so a direct file access will not happen on every call. There is an edge case, most developers aren’t aware of: A file … Read more

Problem with using get_template_part() in footer

It looks like the code in contactform.php may be causing issues. These lines, specifically: global $wp; wp_redirect(home_url($wp->request)); exit; The exit statement may be stopping execution of the rest of the script. If you want to process form data, you should be checking for it and processing it instead of just running the redirect and exit … Read more

get_template_part in admin

Yes, get_template_part() does work on Admin pages. Here is how I tested: Add this to functions.php theme (or child theme) file: add_action( ‘admin_menu’, ‘wpse_99662_register_admin_test_page’ ); function wpse_99662_register_admin_test_page() { add_menu_page( ‘Admin Test Page’, ‘Admin Test Page’, ‘manage_options’, ‘admin_test_page’, ‘wpse_99662_admin_test_page’ ); } function wpse_99662_admin_test_page() { echo ‘<h2>Admin Test Page</h2>’; get_template_part( ‘admin’, ‘test’ ); } The admin-test.php file … Read more

How to pass variables with get_template_part?

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 … Read more