WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

    echo $your_query->post->post_content;

share|improve this answer

Your Answer


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.