Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
$args = array( 'whatever' => 'and_so_on' );
query_posts( $args );

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

share|improve this question
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 '11 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 '11 at 12:26
    
fun as it is: i pushed it on the stage 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 '11 at 1:59
add comment

2 Answers

up vote 1 down vote accepted

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

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

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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