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.

Some of my template tags are playing up, and they have left me confused.

On one site, that has been live for over a year without any of these issues, on all the pages that have custom query loops, the_content() was repeating the first entry. I replaced that line with echo get_the_cotent($post->ID), which I thought was totally equivalent, and it solved the problem.

Now, I have a very similar issue with another site. Trying to fetch and display content from child pages, I have this code block:

global $post;
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
$children = get_page_children($post->ID,$all_wp_pages);
foreach($children as $child){

    ?>
    <div class="childPage">
    <h3><?php the_title($child->ID); ?></h3>
    </div>  
    <?php
}

but this just repeats the title of the parent page.

However, if I replace the_title with echo get_the_title( is works as expected.

I am only assuming these are comparable issues, the certainly have similar symptoms and solutions.

share|improve this question
add comment

1 Answer

Post ID is not an argument in the_title() (see Codex article). Accepted arguments are:

the_title( $before, $after, $echo );

Take a look at the source code. The function the_title() calls get_the_title() with no arguments, whereas get_the_title() takes a Post ID as its only argument. If you want the title of a post/page other than the current one in the query, stick with echo get_the_title(....

Edit: BTW, Post ID is an argument for neither the_content() nor get_the_content().

share|improve this answer
    
It works, though. –  Mild Fuzz Sep 8 '11 at 14:43
    
@Mild Fuzz I guess it's because you messed with the global... –  kaiser Sep 8 '11 at 15:10
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.