get_template_part inside get_template_part?

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();
etc.

// 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)?

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

Leave a Comment