From your comment: (formatted for brevity)
The cute thing is I debugged that
TEMPLATE_MODULE_DIR . 'my-template.php'
and the path in a plugin’s subfolder is right
in fact as I said in my post, with
include_once
it loads perfectly
So because you said it’s in a plugin subfolder (in wp-content/plugins
), then as I said in the comment, it’s normal if get_template_part()
or locate_template()
did not load the template.
And that’s because locate_template()
(which is used by get_template_part()
) only searches templates in the active theme’s folder in wp-content/themes
and wp-includes/theme-compat
if necessary, so for templates in other places like a plugin folder, you would need to use require
or include
, or their “_once” version. Or there’s load_template()
if you want to use it instead.
Try placing a copy of your my-template.php
in the active theme folder and add “test loading from the active theme folder” somewhere in the template, then see if get_template_part()
and/or locate_template()
now loads the template?