Ever tried this?

// template file
do_action( 'my_hook' );

// ex. functions.php
function my_hooked_template_part() {
  get_template_part( 'my_loop_part_file', 'default' );
add_action( 'my_hook', 'my_hooked_template_part' );

// my_loop_part_file-default.php
get_template_part( 'query', 'default' );
if ( have_posts() ) {
while ( have_posts() ) : the_post();

// query-default.php
get_posts( array( 'whatever' => 'and_so_on', ) );

Maybe it's my setup, but it won't load the file. Could it be that it's too late for loading some other file inside? Can anyone confirm or this just a drawback of using the get_template_part() function (only one file - no nesting)?

  • 1
    I have recreated your example and files load fine. Check your actual code for typos or post it here so we can see it in details.
    – Rarst
    Jan 3, 2011 at 10:47
  • 1
    Does it really not load the file, or does it just not show anything? If you add var_dump(__FILE__) to each file, can you see that output?
    – Jan Fabry
    Jan 3, 2011 at 12:26
  • Fun as it is: I pushed it on the staging server and everything works out fine. I guess it's in connection with the wp_cron_bla notice I get from time to time in my local setup. Thanks for your help guys!
    – kaiser
    Jan 4, 2011 at 1:59

2 Answers 2


If your comments in the code above reflect the file names then it's a dash vs. underscore mistake.
Name of the second included file should be query-default.php

  • No, it's not. It's just a simplified example. But thanks for the look up! Already changed.
    – kaiser
    Jan 3, 2011 at 1:18
  • marked this as solution even if not :)
    – kaiser
    Feb 24, 2011 at 8:19

From the get_template_part codex:

<?php get_template_part( 'loop', 'index' ); ?>

will do a PHP require() for the first file that exists...

So it should just be a standard require that you can put anywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.