This code is from my page single-publication.php
.
It outputs the relevant custom fields etc (here wrapped in template tags), but the_content()
won’t output the post content. I’ve resorted to using $post->post_content
(which works), but the mystery remains:
<div class="publication-info">
<?php printf("<h2>%s</h2>", get_the_title() ); ?>
<div class="publication-meta publication-credit"><?php the_publication_credit(); ?></div>
<div class="publication-meta publication-date"><?php the_publication_date(); ?></div><br />
<div class="publication-blurb" style="font-family:sans-serif;"><?php echo $post->post_content; // the_content() doesn't work. Why not? ?></div>
</div>
What’s going on here?
EDIT: I was driven to ask this question because I believed – mistakenly, as it turns out – that $post
working and get_the_title()
returning a title were an ironclad sign of being inside the loop. But apparently this is not the case. cf Codex on The Loop (second para) and Codex on get_the_title() (parameter list). Can anyone explain?
Some post-related data is not available to get_posts by default, such as post content through
the_content()
, or the numeric ID. This is resolved by calling an internal functionsetup_postdata()
, with the $post array as its argument:See Access all post data
There’s a good chance your HTML is not included in the loop. Make sure your code looks like this: