I have this loop in my wordpress site which displays the latest posts with their titles, I want to display the post content after the title. I normally retrieve it with the function get_the_content but I cannot make it work in this case. This is the loop:
while ( $q_query->have_posts() )
{
$q_query->next_post();
$question = get_post($q_query->post);
$loophtml = $loophtml . "<li><span class='list-question-title'>" . "<a class='list-answer-link' href='" . get_permalink($question->ID) ."'>" . $question->post_title . "</a></span>";
$loophtml = $loophtml . "<span class='list-number-answers'>" . get_comments_number($question->ID) . " comentarios</span> · <a href='" . get_permalink($question->ID) ."'>Comentar</a>";
$loophtml = $loophtml . "</li>";
}
Anyone knows how I could do it? Thanks
try this instead:
A little unusual Loop structure you have there.
get_the_content()
works inside the Loop and with global variables set up. And you are not setting up those global variables.To work with your current code it will be something like:
To make template tags work properly you need to use
setup_postdata()
, see examples inget_posts()
documentation.