WP_query returns error when used for custom widget

UPDATE: Okay, Looking at the Error, it should be easy. Just remove any Whitespaces or Clear Lines at the end of your Plugin file after the last “?>”.

http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Did you copy&paste the code here? Because it seems like you have some whitespaces that should not be there in the line

<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query-    >the_post();  ?>

If you remove the whitespaces (like this:

<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();  ?>

), it should work.

P.S.: Don’t forget to use

<?php wp_reset_postdata(); ?>

after the

<?php endwhile; ?>

Otherwise it could end up messing with the rest of your page ^^

Happy Coding,
Kuchenundkakao