I was working on creating my first plugin/widget that should display a really simple loop containing only a custom field (image)
I've been testing the loop without any problems in my theme but when I place the loop in my plugin file it generates a fatal error preventing the plugin to b activated. I really don't understand why this happens as the loop works without any problems in the theme.
This is the loop that I'm using:
<?php $args = array(
'posts_per_page' => 3,
'post_type' => 'sponsors',
'orderby' => 'rand',
);
$the_query = new WP_Query( $args ); ?>
<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<li>
<?php
$image = get_field('sponsor');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
And this is the fatal error displayed when activating the plugin:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
I've already solved it another way by using the PHP Code Widget plugin but would like to know why I get this error. If I need to place the full plugin code let me know.