Q: how to include Thumbnail on WP_Query(Wordpress) Hi guys I am working on a calendar in wordpress and my ajax work fine but I have a problem, on the query I need to include the post pic, this is my query
function fnt_get_treatments() {

// what i recive from ajax
$n=(int)$_REQUEST['mm']+1;
$s = DateTime::createFromFormat('Y-m-d', $_REQUEST['yy'].'-'.$_REQUEST['mm'].'-0');
$u = DateTime::createFromFormat('Y-m-d', $_REQUEST['yy'].'-'.$n.'-0');
// query from the db
$query = new WP_Query(
    array(
        'post_type' => 'tribe_events',
        'post_status' => array(
            'publish'
        ),
        array(
            'after'     => $s,
            'before'    => $u,
            'inclusive' => true,
        ),
        'order'   => 'DESC',
    )
);

// return the data on json format

echo json_encode($query->posts);
die(); // end the script

}
the result is fine, is exactly what i want, but i dont know how to include the post picture cause on the json each object have everything but not the pic url, can anyone help me, i am sure thatś simple but i am new

A: First of all a little modification to your query. You have mentioned the 'date_query' array but have forgotten to set the key date_query
$query = new WP_Query(
    array(
        'post_type' => 'tribe_events',
        'post_status' => 'publish',
        'date_query' => array(
            'after'     => $s,
            'before'    => $u,
            'inclusive' => true,
        ),
        'order'   => 'DESC',
    )
);

And after that instead of doing anything for getting the thumb and slowing down the query you can simply use thumbnail function inside the loop, and you can get any size as per your requirement.
Copy the below code to your loop if you want to display the default size,
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
    the_post_thumbnail();
} 

And if custom size is needed, then you can use the following,
// without parameter -> Post Thumbnail (as set by theme using set_post_thumbnail_size())
the_post_thumbnail();

the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
the_post_thumbnail('medium_large');    // Medium Large resolution (default 768px x 0px max)
the_post_thumbnail('large');           // Large resolution (default 1024px x 1024px max)
the_post_thumbnail('full');            // Original image resolution (unmodified)

the_post_thumbnail( array(100,100) );  // Other resolutions

Page Reference - Post Thumbnail
Hope this once helps ;)
