I created a simple load more ajax button for a wordpress theme, using jquery and php. i'm able to load more posts, but im trying to set the div's background image to the posts thumbnail in my functions.php file using echo, however im not sure how? i tried creating the variable and passing it in the url, but it did not work. Heres my code:
add_action( 'wp_ajax_load_more', 'load_more' );
function load_more() {
// load more posts
$paged = $_POST['page']+1;
$ppp = $_POST['ppp'];
$query = new WP_Query( array(
'post_type' => 'project',
'status' => 'publish',
'order' => 'ASC',
'posts_per_page' => $ppp,
'paged' => $paged
) );
if($query->have_posts()):
while($query->have_posts()): $query->the_post();
$thumbnail = the_post_thumbnail_url();
echo '<div class="col-lg-4 col-md-6">';
echo '<div class="project">';
echo '<div class="project-content">';
echo '<div class="project-img" style="background:url( THUMBNAIL HERE )">';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
endwhile;
endif;
wp_reset_postdata();
die();
```}