0

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!

2 Answers 2

1
$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();
0
$your_query = new WP_Query( $args );
while( $your_query->have_posts() ) :
    $your_query->the_post();

    echo $your_query->post->post_content;

endwhile;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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