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.

How do I get the $post Variable in a WP_Query started loop? I have to get the excerpt, raw $post->post_content and further things. This is why I have to get Access to the Variable itself.

How am I able to do this?

Thank you in advance!

share|improve this question

2 Answers 2

$query = new WP_Query( $args );
while( $query->have_posts() ) {
    // this fills in the $post global with the next post from the query
    $query->the_post();
    // we're now ina  classic wordpress loop, and can use all the usual stuff
    the_title();
    the_content();
    echo $post->post_content;
}
// lets clean up after ourself so else we might mess up other queries and function calls
wp_reset_postdata();
share|improve this answer
$your_query = new WP_Query( $args );
while( $your_query->have_posts() ) :
    $your_query->the_post();

    echo $your_query->post->post_content;

endwhile;
share|improve this answer

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.